public class InnerClassPra {
class a{
}
public static void main(String[] args) {
a a1 = new a();
}
}
为什么错误?

解决方案 »

  1.   

    class a{
    }↑这个是什么意思?
      

  2.   

    你这种情况, 内部类要在用的话, 要像这样(outer代表外部类,inner代表内部类):
    Outer out = new Outer();
    Outer.Inner in = out.new Inner();或者Outer.Inner in = new Outer().new Inner();PS:在外部类的静态方法中实例化内部类对象,必须先创建外部类对象, 内部类属于外部类的成员
      

  3.   

    Outer out = new Outer();
    Outer.Inner in = out.new Inner();
      

  4.   

    内部类a,如果是静态的,(外部类静态方法)可以直接new,如果是非静态的,则要通过外部类实例去new
    所以,要么改成static class a,要么a a1 = new InnerClassPra().new a();
      

  5.   

    public class test { static class a{

    }

        class b{

    }
     
        public void aaa()
        {
         b b1 = new b(); //能直接实例化普通内部类
        }
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    a a1 = new a(); //main为静态方法,能直接实例化静态内部类
    b b1 = new b(); //main为静态方法,不能直接实例化普通内部类
    }
    }
      

  6.   

    public class InnerClassPra {
    public static void main(String[] args) {
    a a1 = new a();
    }
    }class a{
    }
    请把类放在innerClass的大括号的外边。。谢谢!!请把牛逼还给牛,,
      

  7.   

    main 是静态方法,如果内部类是静态内部类,才可以直接实例化