[ Java: this 예약어 ]


[ Java: this 예약어 ]

자신의 메모리를 가리키는 this this: 생성된 인스턴스 스스로를 가리키는 예약어 package thisex; public class BirthDay { int day; int month; int year; public void setYear(int year) { this.year = year; } public void printThis() { System.out.println(this); } } package thisex; public class ThisExample { public static void main(String[] args) { BirthDay bDay = new BirthDay(); bDay.setYear(2000); System.out.println(bDay); bDay.printThis(); } } thisex.BirthDay@4eec7777 thisex.BirthDay@4eec7777 this 값은 참조 변수 bDay 출력 값과 같습니다. 클래스 코드에서...


#java #this #자바

원문링크 : [ Java: this 예약어 ]