JAVA 복습하기

서화진·2022년 8월 19일
0

JAVA 학습일지

목록 보기
8/13

1) this

클래스 내에서 참조 변수가 가지는 주소 값과 동일한 주소값을 가지는 키워드.
자신의 주소를 반환하는 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);
	}
}

2) 출력값

no name,1
ch12.Person@36baf30c
ch12.Person@36baf30c


profile
초보 개발자 / 학습일지 : https://velog.io/@dinyyyyy

0개의 댓글