在看毕老师抽象类练习的视频时,觉得他的代码似乎最后没校正,胡乱写了下,并实现了个打印对象各个特征的功能:
abstract class Employee //这个毕老师没加上abstract
{
private String name;
private String id;
private double pay;
Employee(String name,String id,double pay)
{
this.name = name;
this.id = id;
this.pay = pay;
}
public void SituFu() //增加了一个打印各个属性的功能函数
{
System.out.print("name:"+name+",id:"+id+",pay:"+pay);
}
public abstract void work();
}
class Manager extends Employee
{
private int bonus;
Manager(String name,String id,double pay,int bonus)
{
super(name,id,pay);
this.bonus = bonus;
}
public void Situ(Manager x) //针对经理类自己特有的属性,完善了打印的属性的内容
{
x.SituFu();
System.out.println(",bonus:"+this.bonus);
}
public void work()
{
System.out.println("manager work");
}
}
/*
class Pro extends Employee
{
Pro(String name,String id,double pay)
{
super(name,id,pay);
}
public void work()
{
System.out.println("pro work");
}
}
*/
class AbstractTest
{
public static void main(String[] args)
{
Manager M = new Manager("lisi","0002",2000,1000);
M.work();
M.Situ(M); //这里总觉得写的很别扭,还望大手指教;
}
}
|