import java.util.*;
public class AbstractClassTest {public static void main(String[] args) {Person[] people=new Person[2];people[0]=new Employee("张浩",50000,1989,10,1);people[1]=new Student("李明","计算机科学");for(Person p:people)System.out.println(p.getName()+","+p.getDescription);}
}
public abstract class Person {public Person(String n) {name=n;}public abstract String getDescription();public String getName() {return name;}private String name;
}
class Employee extends Person {public Employee(String n,double s,int year,int month,int day) {super(n);salary=s;GregorianCalender calender=new GregorianCalender(year,month-1,day);hireDay=calender.getTime();}public String getDescription() {return String.format("公司雇员,年薪是¥%.2f。", salary);}private double salary;private Date hireDay;
}
class Student extends Person {public Student(String n,String m) {super(n);major=m;}public String getDescription() {return "大学生,专业是"+major+"。";}private String major;
}
张浩,公司雇员,年薪是¥50000.00。
李明,大学生,专业是计算机科学。