Question: Assume that a fruit object, an orange object, and an apple object have been declared and created with the following statements: Fruit fruit = new

Assume that a fruit object, an orange object, and an apple object have been declared and created with the following statements:
Fruit fruit = new GoldenDelicious(); Orange orange = new Orange(); Apple apple = new Macintosh(); Answer the following questions in the text file main. Include a comment with the question, then the code that answers it. 1. Is the object fruit an instance of Fruit? 2. Is the object fruit an instance of Orange? 3. Is the object fruit an instance of Apple? 4. Is the object fruit an instance of GoldenDelicious? 5. Is the object fruit an instance of Macintosh? 6. Is the object orange an instance of Orange? 7. Is the object orange an instance of Fruit? 8. Suppose the method makeAppleCider() is defined only in the Apple class. Can fruit invoke this method? Can apple invoke this method? 9. Does it make sense to add a makeAppleCider() method to the Fruit class? Why or why not? 10. Now suppose the method makeAppleCider() is defined in the Apple, GoldenDelicious, and Macintosh classes. Identify the class of the method that is invoked when apple invokes the makeAppleCider() method. 11. Suppose the method makeOrangeJuice is defined in the Orange class. Can orange invoke this method? Can fruit invoke this method? 12. Is the statement Orange p = new Apple() legal? 13. Is the statement Macintosh p = new Apple() legal? 14. Is the statement Apple p = new Macintosh() legal? Now, create code to verify your answers. You will need to create each class in the inheritance hierarchy. However, you do not need to create a fully-implemented class. For example, here is my implementation of the Fruit class: public class Fruit { public Fruit() { } } You should also create a class called FruitTest that contains the code the verifies your answer to each question. Make sure to label each verification with the question number. For example: // question 1 Code for verification goes here // question 2 Code for verification goes here
Study the following inheritance hierarchy: Fruit Apple Macintosh Golden Delicious Orange
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
