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

来源:互联网 发布:js查找字符串出现次数 编辑:程序博客网 时间:2024/06/03 05:16
错误分析: 
我想在一个外部类为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();    }}
              ---外部调用抽象类必须实现实例化后,才能调内部类。原因是内部类可以调外部类的参数,你外部类是抽象的,怎么可能让你通过内部类来调用一个抽象外部类未实现的方法!?     不能!!!
0 0
原创粉丝点击