父类中private修饰的成员变量可以被子类所继承吗?如果我需要在主函数打印这个private修饰的变量该怎么做?
abstract class YuanGong
{
public String name;
//private 私有成员不能被访问
private String id;
private double pay;
YuanGong(String name,String id,double pay)
{
this.name = name;
this.id = id;
this.pay = pay;
}
abstract public void work();
}
class PuTong extends YuanGong
{
PuTong(String name,String id,double pay)
{
super(name,id,pay);
}
public void work()
{
System.out.println("普通员工工作");
}
public void show()
{
}
}
class test
{
public static void main(String[] args)
{
YuanGong yg = new PuTong("zhangsan","001",2000);
yg.work();
}
}
|