50 lines
900 B
Java
50 lines
900 B
Java
/*
|
|
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
|
* Date: 2022/04/03
|
|
* Description: This is the class of Ostrich, which is a child class of Bird.
|
|
*/
|
|
|
|
public class Ostrich extends Bird {
|
|
/**
|
|
* Constructor. Ostrich always has 10 eggs.
|
|
*
|
|
* @param name
|
|
*/
|
|
public Ostrich(String name) {
|
|
super(name, 10);
|
|
}
|
|
|
|
/**
|
|
* Ostrich can not fly.
|
|
*
|
|
* @return false
|
|
*/
|
|
@Override
|
|
public boolean canFly() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Ostrich is in dangerous.
|
|
*
|
|
* @return true
|
|
*/
|
|
@Override
|
|
public boolean isDangerous() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Test.
|
|
*/
|
|
public static void testOstrich() {
|
|
Ostrich o1 = new Ostrich("Ostrich1");
|
|
System.out.println(o1.canFly() == false);
|
|
System.out.println(o1.getName() == "Ostrich1");
|
|
System.out.println(o1.getNumOfEggs() == 10);
|
|
System.out.println(o1.getLegs() == 2);
|
|
System.out.println(o1.isDangerous() == true);
|
|
}
|
|
|
|
}
|