引用. = this.
this存储的是对象的地址。因为this是实例对象才能调用
static 方法中不能出现this,因为static是静态的,不需要实例化能直接调用,内部语法不存在this,this只针对于实例变量。
代码没得到复用-----------------------解决办法this(实参){只能出现在构造方法第一行,前边不能出现代码,而且只能出现一次}------------------>保证了不会重复堆的创建。
练习
public class bankCard {
private String name;
private String cardNumber;
private int cardSum;
//构造方法
public bankCard(String name, String cardNumber, int cardSum) {
this.name = name;
this.cardNumber = cardNumber;
this.cardSum = cardSum;
}
//get/set方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}
public int getCardSum() {
return cardSum;
}
public void setCardSum(int cardSum) {
this.cardSum = cardSum;
}
public void deposit(int money){
int i = this.cardSum - money;
this.cardSum = i;
System.out.println(name + "的当前余额为" + this.cardSum);
}
public void whihdrawal(int money){
int i = this.cardSum + money;
this.cardSum = i;
System.out.println(name + "的当前余额为" + this.cardSum);
}
public void show_cardSum(){
System.out.println(this.cardSum);;
}
}