package p1;public interface SayMe {
void say();
}package p2;import p1.SayMe;public class Person {
protected class PersonSayMe implements SayMe{
public void say(){
System.out.println("PersonSayMe");
}
}
protected void walk(){
System.out.println("Person walk");
}
}package p3;import p2.Person;
import p1.SayMe;public class FeMale extends Person{
public SayMe getSayMe(){
return new PersonSayMe(); //为什么这个不能继承Person 的 PersonSayMe ????
}

public static void main(String[] args){
new FeMale().walk();
}
}

解决方案 »

  1.   

    PersonSayMe是受保护的可以被不同包的子类继承,但是不能被不同包的类访问
      

  2.   

    因为你的PersonSayMe是一个内部类,并且不是static的,其相当于Person 的字段一样,怎么才能使用字段,先有Person 才行这样该就可以了public class FeMale extends Person{
        public SayMe getSayMe(){
            return new FeMale().new PersonSayMe(); //为什么这个不能继承Person 的 PersonSayMe ????
        }
        
        public static void main(String[] args){
            new FeMale().walk();
        }
    }或者将protected class PersonSayMe改为protected static class PersonSayMe