1. write out the output for each of the following: Ca) class Animal void whoAmIo
ID: 3754933 • Letter: 1
Question
1. write out the output for each of the following: Ca) class Animal void whoAmIo system.out.println("I am a generic class oog extends Animal void whoAmIO system.out.print1nc"I am a Dog."i J) lass cow extends Anima void whoAmIO system.out.printInC"I am a ow.": class snake, extends Animal void whoamIO system.out.printlnC"I am a println("I am a Snake."; public class RuntimepolymorphismDemo t public static void main(string[] args) Animal ref1 new AnimalO; Animal ref2- new DogO: Animal ref3 new Cow Animal ref4 new SnakeO; ref1.whoAmI Q ref2.whoAmIO ref3.whoAmIO ref4.whoAmIOExplanation / Answer
1) I am a generic Animal
2) I am a Dog
3) I am a Cow
4) I am a Snake
beacuse here parent class holds the child class objects and then When the same method is defined in
the both classes JVM invokes the method in the class whose object is created ( i. e is child class)
so each time method in the child class is invoked
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.