ProgrammingModerateInfosys DSE · Wipro Elite

What is printed?

What is printed?
class A {
    A() { this(1); System.out.print("0"); }
    A(int x) { System.out.print("1"); }
}
class B extends A { B() { super(); System.out.print("b"); } }
// main: new B();
  1. A. 01b
  2. B. 10b
  3. C. 1b0
  4. D. b10

Correct answer: B. 10b

A() delegates to A(int) first (prints 1), then its own body prints 0, then B's body prints b.

More OOP with C++ and Java questions

Exams that ask this topic