abstract class Emoloyee
{
private String name;
private String ID;
private double pay;
public Emoloyee(){}
public Emoloyee(String name,String ID,double pay)
{
this.name = name;
this.ID = ID;
this.pay = pay;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setID(String ID)
{
this.ID = ID;
}
public String getID()
{
return ID;
}
public void setpay(double pay)
{
this.pay = pay;
}
public double getpay()
{
return pay;
}
public void show()
{
System.out.println(name+ID+pay);
}
public abstract void work(); //抽象类
}
class manager extends Emoloyee
{
private int bonus;
public manager(){};
public manager(String name,String ID,double pay)
{
super(name,ID,pay);
this.bonus = bonus;
}
public void work()//调用抽象类
{
System.out.println("manager work");
}
}
class professical extends Emoloyee
{
public professical(){};
public professical(String name,String ID,double pay)
{
super(name,ID,pay);
}
public void work()//调用抽象类
{
System.out.println("professical work");
}
}
class Emoloyeetext
{
public static void main(String[] args)
{
manager e = new manager("马云","albb01",300000);
e.show();
manager e1 = new manager();
e1.setName("刘强东");
e1.setID("jingdong01");
e1.setpay(300000);
professical p = new professical("任正非","albb02",300000);
p.show();
professical p1 = new professical();
p1.setName("刘在石");
p1.setID("jingdong02");
p1.setpay(300000);
//多态
Emoloyee E = new manager();
E.show();
Emoloyee m1 = new professical();
m1.show();
manager m2 = (manager)E;
m2.show();
}
} |
|