标签:his nbsp xtend public div sys ram int bsp
package Tian; public class Actor{ String name; Pet pet;
package Tian; public final class Bear extends Pet { public void run(){ System.out.println("我是雄二,我喜欢蜂蜜"); } }
package Tian; public class Cat extends Pet{ public void run(){ System.out.println("我是小猫,我正在给主人收集金币"); } }
public Actor(String name, Pet pet) { super(); this.name = name; this.pet=pet; } //主人正在跑的方法 public void run(){ System.out.println(name+"正在跑"); pet.run(); } }
package Tian; public class Dog extends Pet{ public void run(){ System.out.println("我是旺财,我为主人做贡献"); } }
package Tian; public class Pet { public void run(){ System.out.println("就是跑"); } }
package Tian; public class Test { /** * @param args */ public static void main(String[] args) { Actor a=new Actor("金枪小帅",new Bear()); a.run(); } }
标签:his nbsp xtend public div sys ram int bsp
原文地址:http://www.cnblogs.com/zyy1130/p/6699180.html