作者: doevents 时间: 2013-9-25 08:22
如果是私有的,虽然继承了父类,还是不能用的,
class FatherClass{
private String name;
public int age=24;
public String show(){
return "臭美灯";
}
public String toString(){
return "[name="+name+",age="+age+"]";
}
}
class ChildClass extends FatherClass{
}
public class Demo{
public static void main(String[] args){
ChildClass c=new ChildClass();
System.out.println(c.name);//出错,无法访问
System.out.println(c.age);
}
}
class ChildClass extends FatherClass{
public int age=25;
}
public class Demo{
public static void main(String[] args){
FatherClass fc=new FatherClass ();
ChildClass c=new ChildClass();
System.out.println(fc.show());
System.out.println(c.age);