m_7_maranda
m_7_maranda
2017-10-29 02:26

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

  • 类与继承
  • java

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条回答