里面的元素如果不这么写,还可以怎么写?

来源:12-1 综合练习

慕数据3565510

2017-05-18 02:56

car [ ] carForRent={new passengerCar(1,"奥迪A4",500,4),

new passengerCar(2,"马自达6",400,4),

new pickUp(3,"皮卡雪6",450,4,2),

new passengerCar(4," 金龙 ",800,20),

 new trunk(5,"松花江",400,4),

new trunk(6,"依维柯",1000,20)};

比如 new trunk(6,"依维柯",1000,20)如果不直接在这里写,在子类里写?怎么写?括号里的6,"依维柯",1000,20是对象的属性?



写回答 关注

2回答

  • 慕数据3565510
    2017-05-19 01:18:33

    比如写成

    passengerCar a1=new passengerCar(1,"奥迪A4",500,4);

    passengerCar a2=new passengerCar(2,"马自达6",400,4);

    pickUp b1=new pickUp(3,"皮卡雪6",450,4,2);

    passengerCar a3=new passengerCar(4," 金龙 ",800,20);

    trunk c1=new trunk(5,"松花江",400,4);

    trunk c2=new trunk(6,"依维柯",1000,20);

    Car carForRent[]=[a1,a2,b1,a3,c1,c2];

    这么写对不对?

  • 我真的不是狐狸精啊
    2017-05-18 08:09:32

    太深奥,回答不起

Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

530696 学习 · 6091 问题

查看课程

相似问题