Close: #1 Lab 7
This commit is contained in:
38
lab/lab7/Question5/Ostrich.java
Normal file
38
lab/lab7/Question5/Ostrich.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user