public class A {
private String C;
public A(String word) {
this.C=word;
}
}
public class B extends A{
public B(String word) {
super(word);
}
public static void main(String[] args) {
new B("C");
}
}我想问this指向的是B对象,为什么能访问父类的private C字段
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为你是用父类的构造方法访问的。A类里的方法对private修饰的成员变量是有访问权限的。