JAVA-this 关键字

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;

  }

}

原文地址:https://www.cnblogs.com/Doris9301/p/7457679.html