基类protected方法的调用
package a;
public class Base
{
protected void pro()
{
System.out.println("This is a protected method.");
}
}
package b;
import a.Base;
public class Derived extends Base
{
public static void main(String[] args)
{
Derived dr = new Derived();
dr.pro();
}
}
package b;
public class Another
{
public static void main(String[] args)
{
Derived dr = new Derived();
dr.pro(); //error
}
}
package a;
import b.Derived;
public class Another2
{
public static void main(String[] args)
{
Derived dr = new Derived();
dr.pro();
}
}
为什么是这样?
如何思考