this
-
[JAVA]JAVA THISLanguages/Java 2021. 2. 18. 17:12
this가 하는일 자신의 메모리를 가리킴 생성자에서 다른 생성자를 호출 자신의 주소를 반환함 생성자에서 다른 생성자를 호출하는 this this를 이용하여 다른 생성자를 호출할 때는 그 이전에 어떠한 statment도 사용할 수 없다 위와 같이 생성자가 여러개 이고 피라미터만 다른 경우 constructor overloading 이라고 한다 package thisex; class Birthday{ int day; int month; int year; public void setYear(int year) { this.year = year; /*this를 쓰지 않으면 지역변수의 이름과 같기 때문에 자신의 메모리를 가리키는 역할 */ } public void printThis() { System.out.pri..