[Java] this(), this
·
Java
생성자 this() : 생성자에서 다른 생성자 호출 (코드 중복 제거 위해 호출) 1. 조건 - 클래스이름 대신 this 사용 - 다른 생성자 호출시 꼭 첫줄에서만 가능! Test(String sb){ score=91; Test(sb, "가", 88); //에러. Test대신 this써야함, 첫줄x } 2. 예 public class Test { String subject; String type; int score; //1. Test(){ this("수학", "가", 85); //3. 호출 }; //2. Test(String subject){ this(subject, "가", 85); //3. 호출 } //3. Test(String subject,String type,int score){ this.sub..