public CashCard(String number,int balance,int bonus){
this.number=number;//参数number指定给这个对象的number
this.balance=balance;
this.bonus=bonus;
}
//...
}
</div>
复制代码
②在Java中,this()代表了调用另一个构造函数,至于调用了哪一个构造函数,则视调用this()时给的自变量类型与个数而定。
(this()调用只能出现在构造函数的第一行
不然会报 Constructor call must be the first statement in a constructor)