this关键字,显式参数与隐式参数

package com.zhe.yang.study;


/**
 * this关键字,显式参数与隐式参数
 * 在student类中reName方法名称后面得是一个显示参数,是需要方法的调用方传递得
 * 可以在类中直接使用this作为当前对象使用,this可以说是一个隐式参数
 */
public class ThisStudy {
public static void main(String[] args) {
Student s=new Student();
s.setName("y");
s.reName("z");
System.out.println(s.getName());
}
}


class Student{
private String name;


public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}

public String reName(String name){
Student s1=this;
System.out.println(s1.name);
this.name=this.name+name;
return this.name;
}

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章