JLS7 Page158 A private class member or constructor is accessible only within the body of the top level class (§7.6) that encloses the declaration of the member or constructor. It is not inherited by subclasses.class A{ private void x() {} } class B extends A{ private int x() { return 0; } }由此可见私有成员不继承
A private class member or constructor is accessible only within the body of the top level
class (§7.6) that encloses the declaration of the member or constructor. It is not inherited
by subclasses.class A{
private void x() {}
}
class B extends A{
private int x() {
return 0;
}
}由此可见私有成员不继承
private String name = "lucy";
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Student extends Person { public static void main(String[] args)
{
Student s =new Student();
System.out.println(s.getName()); }
}
结果是: lucy
说明是继承了,只是不能直接用.
保护程度就是用 private,public,protected 等标识来区分.