this() (1) 썸네일형 리스트형 [Java] 클래스 생성자 선언 시 사용되는 this와 this() this public class Phone{ // 필드 String company = "Samsung"; String model; int price; // 생성자 public Phone(String model, int price){ this.model = model; // this.필드 = 매개변수 this.price = price; // this.필드 = 매개변수 } } 다음과 같이 Phone 클래스에 필드를 선언하고 그 밑에 생성자를 선언했다. 생성자 매개변수로 model, price를 가진다. 여기서 'this.필드' 이렇게 선언하는 부분이 있는데, 이것은 매개변수와 필드값을 구분하기 위해 객체 자신을 참조한다는 의미로 this를 붙이는 것이다. 상기 코드에서 알 수 있듯이 생성자 매개변수와 필드의.. 이전 1 다음