QuestionQ133

Working with Inheritance

Given:

Question Image

and the following code fragment:

S2 sobj = new S2();  
sobj.display(10, 100);  

What is the result?

  • A Child 10 Child 100 Parent 100
  • B Parent 10 Child 10 Parent 1000
  • C Child 10 Parent 100 Parent 100
  • D A compile time error occurs.
Explanation

Calls made through this or without a qualifier use dynamic method dispatch, so both one-argument calls execute S2.display(int) and print Child 10 and Child 100. The super.display(y) call explicitly invokes S1.display(int), which prints Parent 100.

Community Discussion

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