You will write a Java application that implements the concept of Inheritance and Polymorphism.   Convert the following diagram into java program code. Execute the program and answer the questions listed below.  (SEE IMAGE ATTACHED)   Steps Create five java classes with the given names Apple and Orange classes extends the Fruit class Golden Delicious and McIntosh extends the Apple class Provide common properties for each of the class  Provide unique properties to each of the sub classes  Enable each of the subclasses to inherit common properties from the super classes Create instances of Fruit and Orange as described above Run the program to answer the asked questions

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 4RQ
icon
Related questions
Question

You will write a Java application that implements the concept of Inheritance and Polymorphism.

 

Convert the following diagram into java program code. Execute the program and answer the questions listed below.  (SEE IMAGE ATTACHED)

 

Steps

  1. Create five java classes with the given names
  2. Apple and Orange classes extends the Fruit class
  3. Golden Delicious and McIntosh extends the Apple class
  4. Provide common properties for each of the class 
  5. Provide unique properties to each of the sub classes 
  6. Enable each of the subclasses to inherit common properties from the super classes
  7. Create instances of Fruit and Orange as described above
  8. Run the program to answer the asked questions
Suppose that Fruit, Apple, Orange, GoldenDelicious, and McIntosh are defined in the following
inheritance hierarchy:
Fruit
Apple
Orange
Goldendelicious
lstosh
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 instanccof 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?
1. Is the statement McIntosh p = new Apple() legal?
m. Is the statement Apple p = new McIntosh() legal?
n. True or False: You can always successfully cast an instance of a subclass to a superclass.
o. True or False: You can always successfully cast an instance of a superclass to a subclass.
Transcribed Image Text:Suppose that Fruit, Apple, Orange, GoldenDelicious, and McIntosh are defined in the following inheritance hierarchy: Fruit Apple Orange Goldendelicious lstosh 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 instanccof 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? 1. Is the statement McIntosh p = new Apple() legal? m. Is the statement Apple p = new McIntosh() legal? n. True or False: You can always successfully cast an instance of a subclass to a superclass. o. True or False: You can always successfully cast an instance of a superclass to a subclass.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage