ProgrammingVery hardWipro Elite · TCS NQT Prime

What is printed?

What is printed?
class A {
    void f() { System.out.print("A"); g(); }
    void g() { System.out.print("a"); }
}
class B extends A {
    void f() { super.f(); System.out.print("B"); }
    void g() { System.out.print("b"); }
}
// main: new B().f();
  1. A. AaB
  2. B. ABa
  3. C. AabB
  4. D. AbB

Correct answer: D. AbB

super.f() runs A.f, but its call g() is virtual on the B object, so B.g prints b; then B.f prints B.

More OOP with C++ and Java questions

Exams that ask this topic