[原创]   自定义类的对象作为向量元素  实例_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 12162 | 回复: 0   主题: [原创]   自定义类的对象作为向量元素  实例        下一篇 
    本主题由 guoyongwei 于 2013-3-13 11:30:48 置为精华
yongweiguo
注册用户
等级:上尉
经验:593
发帖:32
精华:7
注册:2013-3-11
状态:离线
发送短消息息给yongweiguo 加好友    发送短消息息给yongweiguo 发消息
发表于: IP:您无权察看 2013-3-12 11:59:10 | [全部帖] [楼主帖] 楼主

/*

 * 自定义类的对象作为向量元素

 * @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;
}
}




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论