ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
class Parent {
    protected int score = 50;
    int getScore() { return score; }
}
class Child extends Parent {
    Child() { score += 10; }
}
class GrandChild extends Child {
    GrandChild() { score *= 2; }
}
// in main:
System.out.println(new GrandChild().getScore());
  1. A. 120
  2. B. 100
  3. C. 60
  4. D. 50

Correct answer: A. 120

Construction order is Parent (score=50) -> Child (score=50+10=60) -> GrandChild (score=60*2=120); getScore() is inherited unchanged and simply reads the final shared score field: 120.

More OOP with C++ and Java questions

Exams that ask this topic