Question: Suppose the class Sub extends the class Sandwich. Which of the following assignments are legal? Sandwich x = new Sandwich(); Sub y = new Sub();

Suppose the class Sub extends the class Sandwich. Which of the following assignments are legal?

Sandwich x = new Sandwich();
Sub y = new Sub();
a. x = y;
b. y = x;
c. y = new Sandwich();
d. x = new Sub();

Step by Step Solution

3.43 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a x y is legal because Sub is a subclass of Sandwich so an object ... 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 Concepts Late Objects Questions!