클래스 내에서 참조 변수가 가지는 주소 값과 동일한 주소값을 가지는 키워드.
자신의 주소를 반환하는 this.
package ch12;
public class Person {
String name;
int age;
public Person()
{
this("no name", 1);
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void showPerson()
{
System.out.println(name + "," + age);
}
public Person getPerson() {
return this;
}
public static void main(String[] args) {
Person person = new Person();
person.showPerson();
System.out.println(person);
Person person2 = person.getPerson();
System.out.println(person2);
}
}
no name,1
ch12.Person@36baf30c
ch12.Person@36baf30c