Defining an abstract "Role" has member variables such as name, age, gender, etc
* 1) it is required to hide all the variables as much as possible (private if it can be private, public if it can be protected),
* read and write variables through Getter() and Setter(). With an abstract play() method
* the method does not return any values and defines at least two construction methods. There are several uses of this in Role class.
* 2) derive an "Employee" class from the Role class, which has all members of the Role class (except the constructor)
* and expand salary member variable, and add a static member variable "employee number (ID)".
* there should also be at least two construction methods. To reflect the usage of this and super, you need to override the play() method,
And provide a final sing() method.
* 3) the "manager" class inherits the "Employee" class. There is a final member variable "vehicle"
* make the Manager and employee objects in the main() method, and test the methods of these objects.
package jing.able; /** * @author: panjing * @describe: Defining an abstract "Role" has member variables such as name, age, gender, etc * 1)It is required to hide all the variables as much as possible (to be private, to be protected, not to be public), * Then read and write variables through Getter() and Setter(). With an abstract play() method * This method does not return any values and defines at least two construction methods. There are several uses of this in Role class. * 2)Derive an "Employee" class from the Role class, which has all members of the Role class (except the constructor) * And expand salary member variable, and add a static member variable "employee number (ID)". * There should also be at least two construction methods. To reflect the usage of this and super, you need to override the play() method, * And provide a final sing() method. * 3)"Manager"Class inherits the "Employee" class. There is a final member variable "vehicle" * Make the Manager and employee objects in the main() method and test their methods. * @date: 2019/4/25 * @time: 13:24 */ public class AbstractRole { public static void main(String[] args) { Role role = new Employee("zhangsan",18,100000); role.play(); } } abstract class Role{ /** * Decorated with private, so you need to use getter and setter to get and modify */ private String name; private int age; private String sex; public abstract void play(); //Abstract method public Role(String name,int age){ this.name = name; this.age = age; } public Role(String name,int age,String sex){ this(name,age); //Call the above constructor this.sex = sex; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } } class Employee extends Role{ public double salary; public static int ID; public Employee(String name, int age,double salary) { super(name, age); this.salary = salary; } public Employee(String name, int age, String sex,double salary) { super(name, age, sex); this.salary = salary; } @Override public void play() { System.out.println(this.getName() + "stay"+this.getAge()+"Play a game"); } //The method of overriding the abstract class Role public final void sing(){ System.out.println(this.getName()+"Singing"); } } class Manager extends Employee { public static final String vehicle = "Benz"; public Manager(String name, int age, double salary) { super(name, age, salary); } }