What will be the output when this code is compiled and run?
public class Test
{
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
b1 = b;
update (b);
update (b1);
}
private void update (Bar bar)
{
bar.x = 20;
System.out.println (bar.x);
}
public static void main (String args[])
{
new Test ();
}
private class Bar
{
int x = 10;
}
}
Correct Answer: 20 20 20 20
Explanation:
Note: This Question is unanswered, help us to find answer for this one
More Java MCQ Questions