ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
class A {
    void show() { System.out.print("A"); }
}
class B extends A {
    void show() { super.show(); System.out.print("B"); }
}
class C extends B {
    void show() { System.out.print("C"); super.show(); }
}
// in main:
A obj = new C();
obj.show();
  1. A. C
  2. B. CBA
  3. C. ABC
  4. D. CAB

Correct answer: D. CAB

The object is a C, so C.show runs: it prints C, then calls B.show, which calls A.show (A) before printing B. Result CAB.

More OOP with C++ and Java questions

Exams that ask this topic