1.注意:在构造方法执行过程中一连串调用了父类的构造方法,
* 父类的构造方法又继续向下调用他的父类的构造方法,但是实际上对象只创建了一个,
*
* 2.思考:super(实参) 这种语法是干啥的
* super(实参)的作用是:初始化当前对象的父类型特征,并不是创建新对象,实际上对象只创建了一个
* 3.super关键字代表什么?
* super关键字代表的就是当前对象的那部分父类型特征
public class SuperTest03 {
public static void main(String[] args) {
CreditAccont ca1 = new CreditAccont();
System.out.println(ca1.getActno() + ","+ ca1.getBanlance() +","+ca1.getCredit());
CreditAccont ca2 = new CreditAccont("1111",10000,0.9);
System.out.println(ca2.getActno() + ","+ ca2.getBanlance() +","+ca2.getCredit());
}
}
class Account{
private String actno;
private double banlance;
public Account() {
super();
}
public Account(String actno, double banlance) {
super();
this.actno = actno;
this.banlance = banlance;
}
public String getActno() {
return actno;
}
public void setActno(String actno) {
this.actno = actno;
}
public double getBanlance() {
return banlance;
}
public void setBanlance(double banlance) {
this.banlance = banlance;
}
}
class CreditAccont extends Account{
private double credit;
public CreditAccont() {
//super();
//this.credit = 0.0; 会默认赋值
}
//编译报错 私有的属性只能在本类中访问
/*
public CreditAccont(String actno, double banlance,double credit) {
this.actno = actno;
this.banlance = banlance;
this.credit = credit;
}
*/
public CreditAccont(String actno, double banlance,double credit) {
//以下两行代码在恰当的位置,正好可以使用:super(actno,balance);
//通过子类的构造方法调用父类的构造方法。
super(actno,banlance);
this.credit=credit;
}
public double getCredit() {
return credit;
}
public void setCredit(double credit) {
this.credit = credit;
}