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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!