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

© 雨下阳光 中级黑马   /  2014-9-25 15:09  /  841 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. interface Inter
  2. {       
  3.         void method();
  4. }
  5.        
  6. class Test
  7. {
  8. static Inter function(){
  9.          return new Inter(){
  10.                  void method() {
  11.                          System.out.print("内部类");
  12.                  }
  13.          };
  14. }
  15.                
  16.                
  17. }
  18. class InnerClassDemo
  19. {
  20.         public static void main(String[] args)
  21.         {
  22.                         Test.function().method();        //Inter in=Test.function();in.method()
  23. }
  24.         }
复制代码

这是匿名内部类一个程序,在匿名内部类的方法method()为什么一定是要public权限的?不然会出错

1 个回复

倒序浏览
好好复习一下接口。
常量 public static final
方法 public abstract
少哪个补哪个,不是说你不写就没有的。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马