实现一个名为Person的类和它的两个子类Student和Employee。Employee有子类Faculty和Staff。Person中的人有姓名、地址和电话号码。 Student中的学生有班级状态(一、二、三、四年级)。将这些状态定义为常量。 Employee中的雇员有办公室、工资。Faculty中的教员有级别。Staff中的职员有职务称号。覆盖每个类中的toString方法,显示类名和人名。
class pe {
final String name="王亮";
final String add="河南省郑州市";//电话
final String call="13223456789";//地址
public void ToString()
{
System.out.print("name is"+this.name+"\n"+"add is"+this.add+"\n"+"call is"+this.call+"\n");
System.out.print(this.getClass()+"\n");
}
}
class student extends pe{
final String clanum ="一";
public void ToString(){
System.out.print("name is"+this.name+"\n"+"calnum is"+this.clanum+"\n");
System.out.print(this.getClass()+"\n");
}
}
class employee extends pe{
String office="10#103室";
String salary ="3400元";
public void ToString(){
System.out.print("name is"+this.name+"\n"+"office is"+this.office+"\n"+"salary is"+this.salary+"\n");
System.out.print(this.getClass()+"\n");
}
}
class faculty extends employee
{
String level;
public void ToString()
{
System.out.print("name is"+this.name+"\n"+"call is"+this.level+"\n");
System.out.print(this.getClass()+"\n");
}
}
class staff extends employee{
String zhicheng="高级";
public void ToString()
{
System.out.print("name is"+this.office+"\n"+"zhicheng is"+this.zhicheng+"\n");
System.out.print(this.getClass()+"\n");
}
}
public class Person {
public static void main(String[] args) {
pe a=new pe();
student b=new student();
employee c=new employee();
faculty d=new faculty();
staff e=new staff();
a.ToString();
b.ToString();
c.ToString();
d.ToString();
e.ToString();
}
}