Close: #1 Lab 7
This commit is contained in:
47
lab/lab7/Question3/Dog.java
Normal file
47
lab/lab7/Question3/Dog.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
||||
* Date: 2022/04/03
|
||||
* Description: This is the class of Dog. Dog has 4 legs and can not fly.
|
||||
*/
|
||||
|
||||
public class Dog extends Animal {
|
||||
/**
|
||||
* Constructor of Dog.
|
||||
*
|
||||
* @param name String
|
||||
*/
|
||||
public Dog(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dog has 4 legs.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@Override
|
||||
public int getLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dog can not fly.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean canFly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
public static void testDog() {
|
||||
Dog d = new Dog("Jack");
|
||||
System.out.println(d.getName() == "Jack");
|
||||
System.out.println(d.getLegs() == 4);
|
||||
System.out.println(d.canFly() == false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user