1. this 참조 변수 —> 내 heap을 이야기 한다.
this는 현재 자신을 가리키는 참조 변수이다.
생성자에서 객체 변수 이름과 매개 변수 이름이 동일한 경우 혼동을 막기 위해 사용한다.
this 가 현재 객체를 참조하고 있기 때문에 this.radius 는 현재 객체가 가지고 있는 변수가 되고
this 가 붙지 않은 radius 는 매개 변수 radius 가 된다.
2. this. (지역변수)
2-1. this. 예제



매개변수의 name과 객체의 name 둘의 이름이 똑같다. 이것을 구분하기 위해 this. 을 사용함. this.name은 heap(객체)의 name을 뜻함.
객체 내에서 현재 객체를 가리키는 참조. 객체 내에서 멤버 변수와 메소드를 참조할 때 사용됨. 주로 멤버 변수와 매개변수의 이름이 같을 때, 멤버 변수를 구분하기 위해 사용
this는 무조건 heap꺼!
3. this()
하지만 this() 붙이면 전혀 다른 의미가 된다.
this() 다른 생성자를 의미한다.
가장 복잡한 생성자 작성후 다른 생성자는 이 복잡한 생성자를 호출하게 할때 사용된다.
3-1. this() 주의사항
1. this()는 반드시 생성자 안에서만 호출이 가능하다 2. this()는 반드시 첫번째 문장이어야 한다 3. this()는 다른 생성자를 호출할 때만 사용하여야 한다.
3-2. this() > 굳이 쓸 필요 x (예제)



근데.. 그냥 [ this.name = "토비"; ] 이렇게 초기화를 더 많이함. 굳이.. this() 를?
this()는 같은 클래스 내에서 다른 생성자를 호출하는 역할. 주로 생성자 오버로딩 시 코드의 재사용성을 높이기 위해 사용
this. 이랑 this()는 완전히 다른 것
Share article