写了几天了,这个错误解决不了,求解
为什么我写到main的时候,在创建数值时一直报The constructor PassengerCar(int, String, String, String) is undefined这个错,哪个大神帮你解答一下
package com.imooc;
父类
public class car {
private int number;//车辆编号
private String name;//车辆名称
private float price;//车辆租金
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
@Override
public String toString() {
return "序号:" +number+"\t"+"名称:"+name+"\t"+"价格:"+price+"\t";
}
}
子类 载客量
package com.imooc;
public class PassengerCar extends car {
private int passenger;
public int getPassenger() {
return passenger;
}
public void setPassenger(int passenger) {
this.passenger = passenger;
}
public PassengerCar(int newNumber,String newName,float newPrice,int passenger) {
super.setNumber(newNumber);
super.setName(newName);
super.setPrice(newPrice);
this.setPassenger(passenger);
}
@Override
public String toString() {
return super.toString()+"载客量:"+passenger;
}
}
子类 载货量
package com.imooc;
public class TruckCar extends car {
private double capacity;
public double getCapacity() {
return capacity;
}
public void setCapacity(double capacity) {
this.capacity = capacity;
}
public TruckCar(int newNumber,String newName,float newPrice,double capacity) {
super.setName(newName);
super.setNumber(newNumber);
super.setPrice(newPrice);
this.setCapacity(capacity);
}
@Override
public String toString() {
return super.toString()+"载货量:"+capacity;
}
}
子类 皮卡
package com.imooc;
public class PickCar extends car {
private int passenger;
private double capacity;
public int getPassenger() {
return passenger;
}
public void setPassenger(int passenger) {
this.passenger = passenger;
}
public double getCapacity() {
return capacity;
}
public void setCapacity(double capacity) {
this.capacity = capacity;
}
public PickCar(int newNumber,String newName,float newPrice,int passenger,double capacity) {
super.setName(newName);
super.setNumber(newNumber);
super.setPrice(newPrice);
this.setPassenger(passenger);
this.setCapacity(capacity);
}
@Override
public String toString() {
return super.toString()+"载客量:"+passenger+"\t"+"载货量:"+capacity;
}
}
main
package com.imooc;
import java.util.Scanner;
public class Initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
//创建汽车对象
car[] cars = new car[5];
cars[0]= new PassengerCar(1,"奥迪A4","500f","4");
cars[1]=new TruckCar(2,"松花江","400f","4")
}
}