日期:2014-05-20 浏览次数:20642 次
package com.test; public class Test { public static void main(String[] args) { GameItem gi1 = new Tank("我军坦克", 110); GameItem gi2 = new Tank("敌军坦克", 120); GameItem gi3 = new Tank("友军坦克", 130); gi1.move(); gi2.move(); gi3.move(); } } abstract class GameItem{ public String type; public int speed; //等等一些共有的属性 public GameItem(){ } //构造的时候初始化所有属性 public GameItem(String type, int speed) { super(); this.type = type; this.speed = speed; } public abstract void move(); } class Tank extends GameItem{ public Tank(String type, int speed){ super(type, speed); } @Override public void move() { System.out.println("是" + type + "在移动,移动速度为:" + speed); } }