Question
Consider the following lines of code below: Evaluate the line marked A. Will this statement compile? If not, explain why. If it does compile, what
Consider the following lines of code below:
Evaluate the line marked A. Will this statement compile? If not, explain why. If it does compile, what is the result?
Evaluate the line marked B. Will this statement compile? If not, explain why. If it does compile, what is the result?
Evaluate the line marked C. Will this statement compile? If not, explain why. If it does compile, what is the result?
Evaluate the line marked D. Will this statement compile? If not, explain why. If it does compile, what is the result?
Evaluate the line marked E. Will this statement compile? If not, explain why. If it does compile, what is the result?
public class VariableScope {
// instance variables - replace the example below with your own
private String tmp;
public String method1()
{
String tmp = "hello"; // A. Evaluate this statement
return tmp;
}
public void method2(String var2)
{
int ctr = 0;
boolean tmp = true; // B. Evaluate this statement
while (tmp)
{
ctr++;
if (ctr > 10)
{
tmp = false;
}
}
}
public void method3(String tmp) // C. Evaluate this statement
{
int ctr = 0;
boolean tmp = true; // D. Evaluate this statement
while (tmp)
{
ctr++;
if (ctr > 10)
{
tmp = false;
}
}
}
public String method4(String tmp)
{
if (tmp.equals("hello"))
{
String tmp = "new value"; // E. Evaluate this statement
return tmp;
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started