代码如下:
public class AbstractDemo {
Employee e1, e2;
public AbstractDemo() {
//初始化雇员对象e1,并显示雇员信息
e1 = new Employee( "wang xiao yue ", 3000.00, "2005/05/20 ", 24);
System.out.println( "name: " + e1.getName());
e1.getInfo();
System.out.println( "salary: " + e1.getSalary());
System.out.println( "hireDay: " + e1.getHireDay() + "\n ");
//初始化雇员对象e2,并显示雇员信息
e2 = new Employee( "tong guang ", 5000.00, "2005/05/20 ", 26);
System.out.println( "name: " + e2.getName());
e2.getInfo();
System.out.println( "salary: " + e2.getSalary());
System.out.println( "hireDay: " + e2.getHireDay());
}
public static void main(String[] args) {
new AbstractDemo();
}
}
//自定义抽象类
abstract class People {
String name;
int gae;
//声明抽象方法
abstract String getName();
abstract int getAge();
}
class Employee extends People {
private double salary;
private String hireDay;
private int age;
//含有参数的构造方法
public Employee(String name, double salary, String hireDay, int age) {
this.name = name;
this.salary = salary;
this.hireDay = hireDay;
}
//用于获取雇员信息的方法
public void getInfo() {
System.out.println( "我是员工 ");
}
public double getSalary() {
return salary;
}