子类用super调用父类有参数构造函数,是否会访问到父类的私有属性?
public class Car{ private int carMoney; //汽车租金 private String carName; //汽车名字 private int carNumb; //汽车序列号 private int carryNum; //载货量 private int passengerNum;//载客人数 public Car(int carNumb,String carName,int carMoney,int passengerNum,int carryNum){ this.carMoney = carMoney; this.carName = carName; this.carNumb = carNumb; this.carryNum = carryNum; this.passengerNum = passengerNum; } public int getCarMoney() { return carMoney; } public void setCarMoney(int carMoney) { this.carMoney = carMoney; } public String getCarName() { return carName; } public void setCarName(String carName) { this.carName = carName; } public int getCarNumb() { return carNumb; } public void setCarNumb(int carNumb) { this.carNumb = carNumb; } public int getCarryNum() { return carryNum; } public void setCarryNum(int carryNum) { this.carryNum = carryNum; } public int getPassengerNum() { return passengerNum; } public void setPassengerNum(int passengerNum) { this.passengerNum = passengerNum; } public void showInfo() { // TODO Auto-generated method stub } } class Sedan extends Car{ public Sedan(int carNumb,String carName,int carMoney,int passengerNum,int carryNum){ super(carNumb,carName,carMoney,passengerNum,carryNum); } } class Pickup extends Car{ public Pickup(int carNumb,String carName,int carMoney,int passengerNum,int carryNum){ super(carNumb,carName,carMoney,passengerNum,carryNum); } }
如上所示,不是说私有属性无法继承吗?那么用super调用构造函数时初始化的是什么?子类没有继承父类的属性啊。可是用以上代码却可以调用子类的构造方法初始化父类的属性。怎么回事?