1.this关键字的使用
a.this关键字代表当前对象
this.属性 操作当前对象的属性
this.方法 调用当前对象的方法
public void sendMessage() {
System.out.print("sendMessage");
}
public float getCpu() {
return cpu;
}
public void setCpu(float cpu) {
this.cpu = cpu;//代表当前对象的属性
this.sendMessage();//代表当前对象的方法
}
封装对象的属性的时候,经常会使用this关键字
自动生成get和set方法
步骤:第一步
第二步: