Constructor
Constructor(생성자) 제어
클래스의 형태
package com.hacademy.reflection5;
public class Product {
private String name;
private String type;
private int price;
private Product() {
this("미설정", "없음", 0);
}
public Product(String name) {
this(name, "없음", 0);
}
public Product(String name, String type) {
this(name, type, 0);
}
public Product(String name, String type, int price) {
this.name = name;
this.type = type;
this.price = price;
}
@Override
public String toString() {
return "Product [name=" + name + ", type=" + type + ", price=" + price + "]";
}
}예제 - 생성자 목록 불러오기
예제 - 생성자를 정하여 불러오기
예제 - 기본 생성자를 이용한 객체 생성
예제 - 매개변수 (String) 생성자 이용한 객체 생성
예제 - 매개변수 (String, String) 생성자 이용한 객체 생성
예제 - 매개변수 (String, String, int) 생성자 이용한 객체 생성
Last updated