this 关键字代表当前对象:
- this.属性 ---操作当前对象的属性;
- this.方法 ---调用当前对象的方法;
封装对象的属性时,经常会使用this关键字;
eg:
package imooc;
public class Telephone{
private float screen;
private float cpu;
private float mem;
public float getScreen(){
return screen;
}
public void setScreen(float screen){
this.screen=screen;
}
}
时间: 2024-12-07 16:32:51