本帖最后由 air鹏 于 2014-9-22 10:24 编辑
class AbstractText
{
public static void main(String[] args)
{
PTWork pt = new PTWork("LiSi","007",1000);
JLWork jl = new JLWork("ZhangSan","001",1000,1000);
}
}
abstract class Work
{
private String name;
private String number;
private int pay;
Work(String name,String number,int pay)
{
this.name=name;
this.number=number;
this.pay=pay;
}
abstract void show();
}
class PTWork extends Work
{
PTWork(String name,String number,int pay)
{
super(name,number,pay);
}
void show()
{
//System.out.println(name+number+pay);显示子类对象的成员变量,
//不过由于这些变量在父类中被private修饰 编译失败
}
}
class JLWork extends Work
{
private int jiangjin;
JLWork(String name,String number,int pay,int jiangjin)
{
super(name,number,pay);
this.jiangjin=jiangjin;
}
void show()
{
//System.out.println(name+number+pay+jiangjin);
}
}
|
|