为什么我protectedMethod()
什至不能调用 Parent 类的对象调用它的方法?
package packageA;
public class Parent{
protected void protectedMethod(){
System.out.println("Hello Parent");
}
}
在另一个包中:
package packageB;
import packageA.Parent;
Public Class Child extends Parent{
public static void main(String[] args) {
Parent parent = new Parent();
parent.protectedMethod(); //illegal
Child child = new Child();
child.protectedMethod(); // legal
}
}