MCQs > IT & Programming > Java > Output when this code is compiled and run? public class Test { static int x = 10; public Test () { Bar b = new Bar (); Bar b1 = new Bar (); update (b); update (b1); } private void update (Bar bar) { bar.x = ++x; System.out.println (bar.x); } public static void main (String args[]) { new Test (); } private class Bar { public int x = 10; } }

Java MCQs

What will be the output when this code is compiled and run?

 public class Test
 {
 static int x = 10;
 public Test ()
 {
 Bar b = new Bar ();
 Bar b1 = new Bar ();
 update (b);
 update (b1);
 }
 private void update (Bar bar)
 {
 bar.x = ++x;
 System.out.println (bar.x);
 }
 public static void main (String args[])
 {
 new Test ();
 }
 private class Bar
 {
 public int x = 10;
 }
 }

Answer

Correct Answer: 11 12

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