class Vehicle
{
Vehicle(String s){
System.out.println("It is Vehicle's constructor...");
}
}class Car extends Vehicle
{
Car(String i){
super(i);
System.out.println("It is Car's constructor...");
}
}
public class test
{
public static void main(String[] args)
{
Car c = new Car("xxxxxxxxxxxxx");
}
}
{
Vehicle(String s){
System.out.println("It is Vehicle's constructor...");
}
}class Car extends Vehicle
{
Car(String i){
super(i);
System.out.println("It is Car's constructor...");
}
}
public class test
{
public static void main(String[] args)
{
Car c = new Car("xxxxxxxxxxxxx");
}
}
你复写了一个有参数的Vehicle的构造函数,那么就不会有没有参数的构造函数
在Car的构造过程中必须要调用到Vehicle的构造函数。
因为Car 没有找到父类 Vehicle 的无参数构造函数,所以编译出错!
这样理解对吗??class Vehicle
{
Vehicle (String s)
{
System.out.println("It is Vehicle's String Constructor...");
}
}class Car extends Vehicle
{
}public class test
{
public static void main(String[] args)
{
Car c = new Car();
}
}