QuestionQ4

Working with Inheritance

Given:

Question Image

What is the output?

  • A C B A
  • B C
  • C A B C
  • D Compilation fails at line n1 and line n2
Explanation

Java inserts an implicit super() call as the first statement of each constructor when no explicit constructor invocation is written. Creating C therefore runs A's constructor, followed by B's constructor, and finally C's constructor, producing A B C.

Community Discussion

No comments yet. Be the first to start the discussion!