本帖最后由 梁世喜 于 2012-10-15 18:33 编辑
简单工厂模式。- package com.liang;
- public class Factory {
- static Vei che=null;
-
- public static Vei getVei(){
- //根据条件需要事例车(Vei)对象
- //if() che=new Car(bank,seat);
- //
- return che;
- }
- }
- //车类
- abstract class Vei
- {
- String bank;//牌子
- int seat ;//座位
-
- private Vei(){}
-
- public Vei(String bank,int seat){
- this.bank=bank;
- this.seat=seat;
- }
- }
- //轿车
- class Car extends Vei
- {
- public Car(String bank,int seat){
- super(bank,seat);
- }
- }
- //卡车
- class Truck extends Vei
- {
- int load;//载重
- public Truck(String bank,int seat,int load){
- super(bank,seat);
- this.load=load;
- }
- }
复制代码 这个抽象类可以吧
|