QuestionQ63

Java Object-Oriented Approach

Given the following:

Question Image

and this code fragment:

Question Image

What is the outcome?

  • A a b c
  • B a c b c b c
  • C a a b a b c
  • D b c b c b c
  • E b c a b b c
Explanation

All three references have the runtime type Badminton, so each play() call invokes the overriding Badminton.play() method. Its super.play() call invokes InDoor.play(), which prints b , followed by Badminton.play() printing c ; this occurs three times. Java instance-method invocation is selected by the object's runtime class, while super invokes the superclass implementation. Java Language Specification, §15.12

Learn more

Community Discussion

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