标签:name override void test 一个 main pac sys ide
1. new 一个抽象的类:
package com.xuzhiwen.test1; abstract class Person { abstract void eat(); }
package com.xuzhiwen.test1; public class TestPerson { public static void main(String[] args) { Person p = new Person() { @Override void eat() { System.out.println("i can eat"); } }; p.eat(); } }
2. new 一个接口:
package com.xuzhiwen.test1; public interface Animal { public void run(); }
package com.xuzhiwen.test1; public class Dog { public static void main(String[] args) { new Animal() { @Override public void run() { System.out.println("run().."); } public void getName(){ System.out.println("getName()..."); } }.getName(); } }
标签:name override void test 一个 main pac sys ide
原文地址:http://www.cnblogs.com/beibidewomen/p/7287674.html