Close: #1 Lab 7

This commit is contained in:
2022-04-03 15:14:47 +08:00
parent 85b623f65f
commit 80ae76b597
53 changed files with 2677 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
/*
* 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);
}
}