Problem

Suppose that Fruit, Apple, Orange, GoldenDelicious, and McIntosh are defined in the follow...

Suppose that Fruit, Apple, Orange, GoldenDelicious, and McIntosh are defined in the following inheritance hierarchy:

Assume that the following code is given:

Fruit fruit = new GoldenDelicious();

Orange orange = new Orange();

Answer the following questions:

a. Is fruit instanceof Fruit?


b. Is fruit instanceof Orange?


c. Is fruit instanceof Apple?


d. Is fruit instanceof GoldenDelicious?


e. Is fruit instanceof McIntosh?


f. Is orange instanceof Orange?


g. Is orange instanceof Fruit?


h. Is orange instanceof Apple?


i. Suppose the method makeAppleCider is defined in the Apple class. Can fruit invoke this method? Can orange invoke this method?


j. Suppose the method makeOrangeJuice is defined in the Orange class. Can orange invoke this method? Can fruit invoke this method?


k. Is the statement Orange p = new Apple() legal?


l. Is the statement McIntosh p = new Apple() legal?


m. Is the statement Apple p = new McIntosh() legal?

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT