1.super关键字必须在构造函数的第一个语句,
2.this和super在调用构造函数时不能在同一个构造函数中使用,因为this和super都需要在第一个语句
3.如果子类在构造函数中没有指定调用具体的父类构造函数,那么java编译器会自动在子类构造函数中添加一个super()。
class Vehicle{ int wheels; int weight; public Vehicle(int wheels,int weight){ this.weight=weight; this.wheels=wheels; } } class Truck extends Vehicle{ int loader; int payload; public Truck(int wheels,int weight,int loader,int payload){ super(wheels,weight); this.loader=loader; this.payload=payload; System.out.println("车轮数:"+wheels+" 车重:"+weight+" 有载人数:"+loader+" 车载重:"+payload); } } public class Test { public static void main(String[] args) { Truck a=new Truck(4,30,50,4); } }