qq_helloworld_124
2018-01-22 19:57
在2.52分时老师说“java中父类引用数组保存子类对象”
这个要如何做呢,以及这个知识点在哪里?
求大神告知,也百度了但答案我看不懂。
Multiple markers at this line
- The constructor Pickup(String, double, int) is
undefined
- The constructor Truck(String, double, int) is
undefined
- The constructor Truck(String, double, int) is
undefined
- The constructor Bus(String, int, int) is undefined
- The constructor Bus(String, int, int) is undefined
- The constructor Bus(String, int, int) is undefined
这是你的错误提示信息,constructor是构造器的意思,undefined表示未定义,就是说你没有这个类的构造器,new不了对象,当然默认对象是可以new的,new Bus(),这样的,里面没有参数
//你把这段语句加到Bus里 public Bus(String name,int num,int moneys){ this.name = name; this.num = num; this.money = moneys; } //这段语句加到Truck里 public Truck(String name,double goods,int moneys){ this.name = name; this.goods = goods; this.moneys = moneys; }
这就是构造器
缺个构造器
父类
子类Truck
子类Bus
方法,
父类数组引用子类对象还是错误,
eclipse提示错误原因:Multiple markers at this line
- The constructor Pickup(String, double, int) is
undefined
- The constructor Truck(String, double, int) is
undefined
- The constructor Truck(String, double, int) is
undefined
- The constructor Bus(String, int, int) is undefined
- The constructor Bus(String, int, int) is undefined
- The constructor Bus(String, int, int) is undefined
不知道自己那一步错了,Car父类与其他子类都是继承关系呀,方法参数什么的也没错呀,
求解答,都卡了两天了。
呃..还是你啊哈哈,这也相当于是刚刚那个问题吧?
Java入门第二季 升级版
530560 学习 · 6091 问题
相似问题