Java Basic- OOP - Interface - Quản lý động vật java - đề tiếng anh
Question1:
Create an interface named as IAnimal with the below method:
void input(): input data from keyboard
void display(): display information
Question2:
Create a class named as Animal which implements the IAnimal interface, and have attributes:
private String name;
private double weight;
+ Create two constructors, in which
- Default constructor
- Constructor with arguments used to assign value for Animal’s attributes.
+ Create get/set methods
+ Implement all methods from IAnimal to input data and display information of Animal
Question3:
Create a class named as Cat which extends from Animal and have an extra attribute:
private String color;
+ Create two constructors, in which
- Default constructor
- Constructor with arguments used to assign value for Cat’s attributes and attributes extended from Animal.
+ Create get/set methods
+ Override all methods from Animal to input data and display information of Cat
Question3:
Create a class named as Chicken which extends from Animal and have some extra attribute:
private int numberOfLeg;
+ Create two constructors, in which
- Default constructor
- Constructor with arguments used to assign value for Chicken’s attributes and attributes extended from Animal.
+ Create get/set methods
+ Override all methods from Animal to input data and display information of Chicken
Question4:
Create the test class named as AnimalTest to do the following action:
1) Create an array for classes: Animal, Cat and Chicken with length 3.
2) Create only one menthod inputDataForAnimal(): used to input data for array of Animal, Cat and Chicken
3) Create only one menthod displayDataOfAnimal(): used to display information of all items in array of Animal, Cat and Chicken.
4) Create main() method to test the above methods