Java OCA OCP Practice Question 1127

Question

Suppose that classes X and Y are subclasses of Z and Z implements the W interface.

Which of the following are true?

  • A. A reference to X can be cast to an object of class Y.
  • B. A reference to Y can be cast to an object of class X.
  • C. A reference to X can be cast to an object of class Z.
  • D. A reference to Y can be cast to an object of class Z.
  • E. A reference to X can be cast to an object of interface W.
  • F. A reference to Y can be cast to an object of interface W.
  • G. A reference to Z can be cast to an object of interface W.


C through G.

Note

References to X and Y objects can be cast to Z and W objects.

References to Z objects can be cast to W objects.

However, references to X and Y objects may not be cast to each other.




PreviousNext

Related