Java输出对象的数组是地址,如何输出其值?

看着视频自学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

慕粉142512354
浏览 6542回答 3
3回答

疯疯癫癫得小猪

Arrays.deepToString()  你这代码真的难看

慕仰0180559

把每个类的toString方法都重写试试

__innocence

我不知道如何解决这个问题,但是,我提醒一下,慕课网发起提问的时候,左边有一个代码语言,你的代码复制在代码语言里会比较好
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java