MCQs > IT & Programming > Java > 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; } }

Java MCQs

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;
 }
 }

Answer

Correct Answer: 20 20 20 20

Explanation:

Note: This Question is unanswered, help us to find answer for this one

Java Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

Java Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it