Question: instanceof + polymorphism java b) Write the missing code where indicated above in order to invoke the method saySomething (String s) using the reference variable

instanceof + polymorphism java b) Write the missing code where indicated abovein order to invoke the method saySomething (String s) using the referenceinstanceof

+ polymorphism java

b) Write the missing code where indicated above in order to invoke the method saySomething (String s) using the reference variable f2. Use any value for s. Explain the output (i.e., why we see each text line in the output). c) Is the following statement valid? Explain. apples [0] = new Orange() ; Fruit + saySomething) void Apple Orange + makeAppleCider) void + saySomething() void + saySomething(s String) void + makeOrangeJuice()oid + saySomething)void GoldenDelicious Mclntosh + saySomething() void + saySomething(s String) void A method saySomething () displays the type of object, e.g., for the Apple class, the method displays "I am an Apple". The overloaded method saySomething (String s) displays the type then the value of s, e.g., for class Apple and s- "hello", the method displays "Apple says: hello!" a) What is displayed on the screen after running the code below public class A2 { public static void main(String[] args) { FruitI 1 fruitsnew Fruit[51: fruits[e]-new Fruit(); fruits[1]-new Apple(); fruits [21 - newOrange( fruits[3]new GoldenDelicious (); fruits[4] - new McIntosh(); for(Fruit fl: fruits)( f1.saySomething(); Fruit[] applesnew Apple[3]; apples [e]new Apple(); apples [1]-new GoldenDelicious (); apples [2]new McIntosh(); for(Fruit f2: apples) //add code here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!