[JAVA] 객체지향 - this
·
Back-End/Java
[작성일: 2023. 01. 25] 생성자 this()같은 클래스 생성자에서 다른 생성자를 호출할 때 사용클래스 이름 대신 this() 사용다른 생성자 호출 시 첫 줄에서만 사용 가능첫 줄이 아닐 경우 에러.코드 중복을 제거하기 위해 생성자들끼리 서로 호출함.class Car2 { String color; String gearType; int door; Car2() { this("white", "auto", 4); } // Car2(String color, String gearType, int door)를 호출 Car(String color) { this(color, "auto", 4); } // Car2(String color, String gearType, ..