外部类为abstract时,出错记录。

错误分析:
我想在一个外部类为abstract类型父类A里建一个其的子类内部类B;在外部其他类中是不能调到内部类(子类B)的,因为外部调用抽象类必须实现实例化后,才能调内部类。
报错:A.B cannot be resolved to a type
Base.Sub3 cannot be resolved to a type

例子:调用内部类;
public class A   {
class B{
        int b = 66666;
        public int getNum(){
            return b;
        }
    }
  public B getB(){
        return new B();
    }
    public static void main(String args[]){
        A a = new A();
        B b =  a.getB();
    }   
}
或者这样:

public class A   {
    public class B{
        int b = 66666;
        public int getNum(){
            return b;
    }
    }
  public static void main(String args[]){
        A a = new A();
        B b =  a.new B();
    }
}
              ---外部调用抽象类必须实现实例化后,才能调内部类。原因是内部类可以调外部类的参数,你外部类是抽象的,怎么可能让你通过内部类来调用一个抽象外部类未实现的方法!?     不能!!!

猜你喜欢

转载自4636.iteye.com/blog/2315224
今日推荐