- interface Inter
- {
- void method();
- }
-
- class Test
- {
- static Inter function(){
- return new Inter(){
- void method() {
- System.out.print("内部类");
- }
- };
- }
-
-
- }
- class InnerClassDemo
- {
- public static void main(String[] args)
- {
- Test.function().method(); //Inter in=Test.function();in.method()
- }
- }
复制代码
这是匿名内部类一个程序,在匿名内部类的方法method()为什么一定是要public权限的?不然会出错 |
|