/* * Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007) * Date: 2022/04/03 * Description: This is the abstract animal class. */ public abstract class Animal { /** * The name for the animal. */ private String name; /** * Constructor * * @param String. The name for the animal. */ public Animal(String name) { this.name = name; } /** * Getter for the name. * * @return String. The name of the animal. */ public String getName() { return name; } /** * Abstract getLegs methods returns as result the animal's number of legs. * * @return int. The number of legs. */ public abstract int getLegs(); /** * Abstract canFly methods returns as result the animal's ability to fly. * * @return boolean. The ability to fly. */ public abstract boolean canFly(); /** * Test. */ public static void testAnimal() { Animal a = new Animal("Animal") { @Override public int getLegs() { return 4; } @Override public boolean canFly() { return false; } }; System.out.println(a.getName() == "Animal"); System.out.println(a.getLegs() == 4); System.out.println(a.canFly() == false); } }