package protectedexample;
public class Animal {
protected void speak(){
System.out.println("default speaking");
}
public void eat(){
System.out.println("default speaking");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Animal a=new Animal();
a.speak();
}
}
package cloning;
import protectedexample.Animal;
public class TestAnimal extends Animal{
/**
* @param args
*/
public static void main(String[] args) {
Animal a=new Animal();
a.speak();//Error is coming Method speak() of class animal is not visible
}
}
上述编译时错误的原因是什么 - 当我知道受保护的成员在任何包中的sublcass中可见时,类动物的方法说()是不可见的