package packa;
public class A
{
public void show()
{
System.out.println("a show run");
}
}
package packb;
public class B
{
public void show()
{
System.out.println("b show run");
}
protected void method()
{
System.out.println("b method run");
}
}
package packdemo;
class PackageDemo extends packb.B
{
public static void main(String[] args)
{
packa.A a =new packa.A();
a.show();
packb.B b= new packb.B();
b.show();
b.method();
}
}
我建立了三个包,当包packa和包packb编译通过后,我再通过javac命令编译包packdemo
结果却是显示:
C:\Program Files\EditPlus 3>javac -d D:\my=java-classes PackageDemo.javaPackageDemo.java:10: 错误: method()可以在B中访问protected b.method(); ^ 1 个错误