package packa;
public class DemoA extends packb.DemoB{
public void show(){
method();
System.out.println("demoa show run");
}
}
package packb;
public class DemoB{
protected void method(){
System. out.println("demob show run" );
}
}
package mypack;
class PackageDemo{
public static void main(String[] args){
packa.DemoA d = new packa.DemoA();
d.show();
packb.DemoB b = new packb.DemoB();
//b.method();// 报错!无法访问 DemoB 中的 protected 修饰的 method 方法
System.out.println("Hello Package!");
}
}
结果是 demoa show run
Hello Package!
不明白结果为什么会是这个??? |
|