m_7_maranda 2017-10-29 02:26 采纳率: 50%
浏览 696

调用父类构造函数super(color,wheel)出错

class Vehicle
{
private String color;
private int wheel;
public Vehicle()
{
System.out.println("调用了Vehicle的无参构造函数");
}
public Vehicle(String color,int wheel)
{
System.out.println("调用了Vehicle的有参构造函数");
this.color=color;
this.wheel=wheel;
}
public void show()
{
System.out.println("颜色为:"+color+" 车轮数量为:"+wheel);
}
public void calc()
{
float velocity=0;
float distance=0;
float t=velocity/distance;
System.out.println("速度为:"+velocity+" 距离为:"+distance+" 行使该距离所需的时间为:"+t);
}
}

class Car extends Vehicle
{
private String co;
private int wh;
public Car()
{
System.out.println("调用了Car的无参构造函数");
}
public Car(String color,int wheel,String c,int w)
{
System.out.println("调用了Car的有参构造函数");
super(color,wheel);
co=c;wh=w;
System.out.println("小车颜色为:"+color+",车轮数量为:"+wheel);
}
public void consume()
{
double oil=0;
float distance=0;
double l=oil*distance;
System.out.println("百公里耗油量为:"+oil+",距离为:"+distance+",行使该距离所耗的油量为:"+l);
}
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-29 03:03
    关注

    super调用必须放在构造函数的第一行。

    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码