Files
oop/lab/lab7/Question8/Start.java
2022-04-03 15:15:13 +08:00

62 lines
2.1 KiB
Java

/**
* Answer to Question.
*
* Answer to Question 1:
*
* - Q: Should the getLegs methods be abstract? Why or why not?
*
* - A: Yes. Because different animal have different number of legs. In animal
* class we didn't define how many legs an animal has.
*
* - Q: Should the canFly methods be abstract? Why or why not?
*
* - A: Yes. Because different animal have different ability to fly. In animal
* class we didn't define how an animal can fly.
*
* - Q: Should the Animal class be abstract? Why or why not?
*
* - A: Yes. Because different animal have different properties. In animal class
* we didn't define how an animal is.
*
* - Q: What kinds of test can you write inside the testAnimal method?
*
* - A: You can write test for the getLegs and canFly methods. Before that, you
* need to inherit the Animal class and override the getLegs and canFly methods.
* Because the Animal class is abstract, you can't create an object of it.
*
* - Q: Can you test object from the Animal, Dog, and Bird classes through the
* Flyer interface? Why or Why not?
*
* - A: No. Because the they didn't implement the Flyer interface. For Animal
* class, you can't because the canFly() method is abstract. For Dog class, you
* can't because it didn't declare it has implement the Flyer interface. For
* Bird class, you can't because the canFly() method is abstract.
*/
public class Start {
public static void main(String[] args) {
Animal.testAnimal();
Dog.testDog();
Bird.testBird();
Magpie.testMagpie();
Ostrich.testOstrich();
Pegasus.testPegasus();
Airplane.testAirplane();
Flyer magpie = new Magpie("Mumomomo");
System.out.println(magpie.getName() == "Mumomomo");
System.out.println(magpie.canFly() == true);
Flyer ostrich = new Ostrich("Ohheyeyeye");
System.out.println(ostrich.getName() == "Ohheyeyeye");
System.out.println(ostrich.canFly() == false);
Flyer pegasi = new Pegasus("Prprprpr");
System.out.println(pegasi.getName() == "Prprprpr");
System.out.println(pegasi.canFly() == true);
Flyer airplane = new Airplane("Shakaraka");
System.out.println(airplane.getName() == "Shakaraka");
System.out.println(airplane.canFly() == true);
}
}