class Machine0 {public void start() {System.out.println("Machine starting");}}interface Plant {void growing();}public class App2 {public static void main(String[] args) {Machine0 machine1 = new Machine0() {@Overridepublic void start() {System.out.println("Camera starting");}};//真正指向的对象是等号后面的有重载method的类Plant plant1 = new Plant() {public void growing() {System.out.println("growing");}};//interfacce本身不能定义对象,但是可以通过后面的真正的类创建一个对象machine1.start();plant1.growing();}}匿名类只能创建一个对象,不能再次实用该类
Anonymous Class
最新推荐文章于 2023-11-10 08:00:00 发布