Question: Given the following class and reference declarations, what can be said about the statement y = (Sub) x? Select the one correct answer. (a) It

Given the following class and reference declarations, what can be said about the statement y = (Sub) x?

// Class declarations: class Super {} class Sub extends Super {} //

Select the one correct answer.

(a) It is illegal at compile time.

(b) It is legal at compile time, but might be illegal at runtime.

(c) It is definitely legal at runtime, but the cast operator (Sub) is not strictly needed.

(d) It is definitely legal at runtime, and the cast operator (Sub) is needed.

// Class declarations: class Super {} class Sub extends Super {} // Reference declarations: Super x = null; Sub y = null;

Step by Step Solution

3.54 Rating (161 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

b The compiler will allow the statement as ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming 8th Questions!