QuestionQ74

Working with Inheritance

Given:

Question Image

What is the outcome?

  • A A B
  • B A C
  • C C C
  • D A ClassCastException is thrown only at line n1.
  • E A ClassCastException is thrown only at line n2.
Explanation

The cast at line n1 succeeds because the object is a C, and C extends A. The cast at line n2 throws ClassCastException because the runtime object is a C, not a B; execution therefore does not reach either test() invocation.

Community Discussion

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