匿名内部类-就是继承父类或实现接口的,这样设计可以简化书写。- interface Animal
- {
- void run();
- }
- interface Person
- {
- void run();
- }
- class Main
- {
- public static void main(String [] args)
- {
- new Animal()
- {
- public void run()
- {
- System.out.println("run.....");
- }
- }.run();
-
- new Person()
- {
- public void run()
- {
- System.out.println("study.....");
- }
- }.run();
-
- }
- }
复制代码 |