看着视频自学java,在父类中重写了toString也无法输出数组的值,求指导。代码如下:
执行类:
ACar car1 = new Bus(1,"金龙客车",5,0);ACar car2 = new Tuck(2,"松花江货车",2,20);ACar car3 = new Pickup(3,"长城皮卡",4,2); ACar [] a = {car1,car2,car3};System.out.println("欢迎使用达达租车系统!");System.out.println("是否需要租车服务,1:是 0:否");Scanner scan = new Scanner(System.in);String input = scan.next();if (input.equals("1")){System.out.println("可以使用的车型如下(编号,车名,乘车人数,载重数量,单价):");for (int i = 0;i<3;i++){ System.out.println(a[i].x); }父类ACar:public abstract class ACar {int ModelsNum; //车型编号String Carname; //车型名称int NumberOfPeople; //载客量int load; //载重量int price; // 每天单价int money; //支付总金额//String[] x = {Carname};Object[] x = {ModelsNum,Carname,NumberOfPeople,load,price};public ACar(int new_ModelsNum,String new_Carname,int new_NumberofPeople,int new_load){this.ModelsNum = new_ModelsNum;this.Carname = new_Carname;this.NumberOfPeople = new_NumberofPeople;this.load = new_load;}public abstract void run();@Overridepublic String toString() {return "ACar [ModelsNum=" + ModelsNum + ", Carname=" + Carname + ", NumberOfPeople=" + NumberOfPeople+ ", load=" + load + ", price=" + price + ", money=" + money + ", x=" + Arrays.toString(x) + "]";} }输出结果:可以使用的车型如下(编号,车名,乘车人数,载重数量,单价):[Ljava.lang.Object;@1b6d3586[Ljava.lang.Object;@4554617c[Ljava.lang.Object;@74a14482
疯疯癫癫得小猪
慕仰0180559
__innocence
相关分类