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;

  }

}

 

posted @ 2017-08-31 12:07  Doris9301  阅读(105)  评论(0编辑  收藏  举报