A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 黑马王冬冬 中级黑马   /  2012-7-28 15:23  /  2268 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. abstract class outer {                  //抽象外部类
  2.         public static void main(String[] args) {
  3.                                                         //如何在main方法中创建内部类的实例
  4.         }

  5.         class inner extends outer {             //继承抽象外部类的内部类
  6.                 System.out.println("inner class");
  7.         }
  8. }
复制代码
昨天回帖的时候,发现了这个问题,请问如何创建该内部类的对象?

4 个回复

倒序浏览
abstract class outer {                  //抽象外部类

        public static void main(String[] args) {

                     new outer(){
                       System.out.println("inner class");         
                   }                                   //如何在main方法中创建内部类的实例

        }



        class inner extends outer {             //继承抽象外部类的内部类

                System.out.println("inner class");

        }

}
回复 使用道具 举报
这样看看可不可以。。。。

QQ截图20120728154808.jpg (28.76 KB, 下载次数: 163)

QQ截图20120728154808.jpg
回复 使用道具 举报
本帖最后由 魏-玉-彪 于 2012-7-28 20:07 编辑

abstract class outer {                  //抽象外部类
        public static void main(String[] args) {
                                             
         直接NEW 一个

     inner  i=new inner();



        }

      


回复 使用道具 举报
  1. public abstract class Test1 {

  2.         /**
  3.          * @param args
  4.          */
  5.         public static void main(String[] args) {
  6.                 // TODO Auto-generated method stub
  7.                 Inner in=new Inner();
  8.                 in.run();
  9.         }
  10.         static class Inner extends Test1//当外部类中的静态方法访问内部类时,内部类也必须是静态的。主函数是静态的,所以被主函数访问的此内部类必须为静态。
  11.         {
  12.                 void run()
  13.                 {
  14.                         System.out.println("Inner class.");//楼主,这条语句是不能直接写在内部类中的吧。
  15.                 }
  16.         }
  17. }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马