Please help with easy first year computer science questions A1 (25 marks) Focus:
ID: 3877321 • Letter: P
Question
Please help with easy first year computer science questions
A1 (25 marks) Focus: OOP basics, Inheritance, and Polymorphisnm Q1. [15 marks] Suppose that Fruit, Apple, Orange, GoldenDelicious, and Mclntosh are defined in the following inheritance hierarchy: Fruit Apple Orange + makeAppleCider)void + makeOrangeJuice) void GoldenDelicious Mclntosh And assume that the following code is given: Fruit fruit - new GoldenDelicious) Orange orange = new Orange(); Answer the following questions, and explain your answer. 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. Can fruit invoke makeAppleCider method? j. Can orange invoke makeAppleCider method? k. Can fruit invoke makeOrangeJuice method? I. Can orange invoke makeOrangeJuice method? m. Is the statement Orange p = new Apple() legal? Is the statement McIntosh p = new Apple() legal? Is the statement Apple p = new McIntosh() legal?Explanation / Answer
ANSWER: (1):-
a) YES, because multi-level inheritance exists here in between GoldenDelicious,Apple and Fruit.
b) No, object of Fruit class i.e. fruit doesnot belongs to Orange.
c) Yes, due to single level inheritance between Apple and Fruit.
d) Yes, due to multi-level inheritance in between GoldenDelicious,Apple and Fruit.
e) Yes, due to multi-level inheritance in between MacIntosh,Apple and Fruit.
f) Yes, due to same class object.
g) No, orange object does not belongs to Fruit class.
h) No, There is no relation between Orange and Apple.
i) Yes, it can do because of multilevel inheritance.
j) No, due to no inheritance possible here.
k) Yes, becasue of single inheritance between orange and Fruit.
l) Yes, due to same class object it is possible.
m) No, due to no inheritance exists there between two.
n) No, but reverse is possible. i.e. Apple p = new McIntosh(); due to single inheritance.
o) Yes, it is legal due to single inheritance exists here.