Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 7 Online
OpenStudy (anonymous):

Assume that Animal extends Object (and assume Animal is an abstract class, no other abstract classes) and that FarmAnimal extends Animal Cow extends FarmAnimal Chicken extends FarmAnimal Assume all the above classes have a default constructor. Which of these statements compile? Animal a1 = new Animal(); ______ Animal a2 = new Cow(); ______ Cow a3 = new Animal(); ______ Cow a4 = new FarmAnimal(); ______ FarmAnimal a5 = new Cow(); ______ Cow a6 = new Cow(); ______ Cow a7 = new Chicken(); ______ Chicken a8 = new Cow(); _____ Chicken a9 = new FarmAnimal(); ______

OpenStudy (anonymous):

Animal a1 = new Animal(); Animal a2 = new Cow(); FarmAnimal a5 = new Cow();

OpenStudy (anonymous):

*assuming this is Java and the rules of polymorphism is the question

OpenStudy (anonymous):

http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html This tutorial should help clear up any confusion

OpenStudy (anonymous):

Animal a1 = new Animal(); doesn't compile! Animal is an abstract class and can't be instantiated. Animal a1 = new Animal(); Does not compile, Animal is abstract Animal a2 = new Cow(); Compiles, Cow is a subclass of Animal and is not abstract Cow a3 = new Animal(); Does not compile, Animal is abstract Cow a4 = new FarmAnimal(); Does not compile, FarmAnimal isn't a subclass of cow (it's superclass) FarmAnimal a5 = new Cow(); Compiles, Cow is a subclass of FarmAnimal Cow a6 = new Cow(); Compiles Cow a7 = new Chicken(); Does not compile, Chicken isn't a subclass of Cow Chicken a8 = new Cow(); Does not compile, Cow isn't a subclass of Chicken Chicken a9 = new FarmAnimal(); Does not compile, FarmAnimal isn't a subclass of Chicken

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!