- this : 인스턴스 자신을 가리키는 참조변수 인스턴스의 주소가 저장되어 있다
모든 인스턴스메서드에 지역변수로 숨겨진 채 존재한다- this(), this(매개변수) : 생성자, 같은 클래스의 다른 생성자를 호출할 때 사용한다
✔ ❗ 생성자 this()와 참조변수 this는 전혀 다른 것이기 때문에 관계를 지으면 안된다 😑❗
class Car{
String color;
String gearType;
int door;
Car (){
//Car (String color, String gearType, int door)을 호출
//코드의 중복을 제거하기 위해서
this("white","auto",4); //값을 넘겨주지 않고 생성할때 기본값을 주기 위해
}
Car (String color){
//Car (String color, String gearType, int door)을 호출
//코드의 중복을 제거하기 위해서
this(color,"auto",4); //값을 넘겨주지 않고 생성할때 기본값을 주기 위해
}
Car (String color, String gearType, int door){
this.color = color;
this.gearType = gearType;
this.door = door;
}
}
car(){
color = "white";
geartype = "auto";
door = 4;
}
car(){
color = "white";
geartype = "auto";
door = 4;
}
car(String color, String gearType, int door){
this.color = "white";
this.geartype = "auto";
this.door = 4;
}