Code in C# (OOP Concept) 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 with proper explanation: I. Is fruit instanceof Fruit? II. Is fruit instanceof Orange? III. Is fruit instanceof Apple? IV. Is fruit instanceof GoldenDelicious? V. Is fruit instanceof McIntosh? VI. Is orange instanceof Orange? VII. Is orange instanceof Fruit? VIII. Is orange instanceof Apple? IX. Suppose the method makeAppleCider is defined in the Apple class. Can fruit invoke this method? Can orange invoke this method? X. Suppose the method makeOrangeJuice is defined in the Orange class. Can orange invoke this method? Can fruit invoke this method? XI. Is the statement Orange p = new Apple() legal? XII. Is the statement McIntosh p = new Apple() legal? XIII. Is the statement Apple p = new McIntosh() legal?
Code in C# (OOP Concept)
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 with proper explanation:
I. Is fruit instanceof Fruit?
II. Is fruit instanceof Orange?
III. Is fruit instanceof Apple?
IV. Is fruit instanceof GoldenDelicious?
V. Is fruit instanceof McIntosh?
VI. Is orange instanceof Orange?
VII. Is orange instanceof Fruit?
VIII. Is orange instanceof Apple?
IX. Suppose the method makeAppleCider is defined in the Apple class. Can fruit invoke this method? Can orange invoke this method?
X. Suppose the method makeOrangeJuice is defined in the Orange class. Can orange invoke this method? Can fruit invoke this method?
XI. Is the statement Orange p = new Apple() legal?
XII. Is the statement McIntosh p = new Apple() legal?
XIII. Is the statement Apple p = new McIntosh() legal?
Trending now
This is a popular solution!
Step by step
Solved in 2 steps