不同包里面的子类继承了父类却访问不了protected权限的问题
父类:
package father;
public class Person{
protected void introduce(){
System.out.println("父类中的introduce函数,拥有protected权限");
}
}
子类:
package son;
import father.Person;
class Student extends Person{
public static void main(String args []){
Person p = new Person();
p.introduce();
}
}
运行后报错:
Student.java:7: 错误: introduce()可以在Person中访问protected
p.introduce();
1个错误
问题:
为什么不同包里面的子类继承了父类,却访问不了父类中protected权限的函数?