Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

liliy

  • one year ago

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(); ______

  • This Question is Open
  1. charpede
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  2. charpede
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  3. charpede
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  4. Meepi
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    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

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.