日期:2014-05-20 浏览次数:20787 次
public class Test { public static void main(String[] args) { Gameitem g1 = new Tank("Tank"); Gameitem g2 = new Tank("Missile"); g1.move(); g2.move(); } } class Gameitem{ public String name; public void move(){ System.out.println(name + " move..."); } } class Tank extends Gameitem{ public Tank(String name){ super.name = name; } } class Missile extends Gameitem{ public Missile(String name){ super.name = name; } }