/*
* 自定义类的对象作为向量元素
* @author gyw
* */
import java.util.*;
public class myVector2 {
public static void main(String[] args) {
Vector a = new Vector();//创建向量 a
a.addElement(new Car2("Audi A8 W12", 5267, 1949, 1471));
a.addElement(new Car2("Benz S600", 5230, 1871, 1485));
a.addElement(new Car2("BMW 760LI", 5212, 1902, 1484));
System.out.println(((Car2)a.elementAt(1)).type);
a.insertElementAt(new Airplane("Boeing 747-400", 70600, 64400, 19300), 1);
System.out.println(((Airplane)a.elementAt(1)).type);
}
}
class Car2 {//声明自定义类Car2
String type;
int length;
int width;
int heigth;
Car2(String type, int length, int width, int heigth) {//构造方法
this.type = type;
this.length = length;
this.width = width;
this.heigth = heigth;
}
}
class Airplane {
String type;
int length;
int width;
int heigth;
Airplane(String type, int length, int width, int heigth) {//构造方法
this.type = type;
this.length = length;
this.width = width;
this.heigth = heigth;
}
}