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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education