Close: #1 Lab 7
This commit is contained in:
38
lab/lab7/Question4/Magpie.java
Normal file
38
lab/lab7/Question4/Magpie.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 Magpie, which is a child class of Brid.
|
||||
*/
|
||||
|
||||
public class Magpie extends Bird {
|
||||
/**
|
||||
* Constructor. Magpie always have 6 eggs.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public Magpie(String name) {
|
||||
super(name, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magpie can fly.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
public boolean canFly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
public static void testMagpie() {
|
||||
Bird bird = new Magpie("Magpie");
|
||||
System.out.println(bird.getName() == "Magpie");
|
||||
System.out.println(bird.getNumOfEggs() == 6);
|
||||
System.out.println(bird.canFly() == true);
|
||||
System.out.println(bird.getLegs() == 2);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user