ex)
class Car() { car() {} //매개변수가 없는 생성자 car(String a, int b) {} //매개변수가 있는 생성자 } public class Car() { public car() {} //컴파일러가 추가해줌 }
ex)
class car() { //car -> this car() //car -> this() }
ex) this
Car(String color, String type, String door) { / this.color = color; this.type = type; this.dorr = dorr; }
ex) this()
public Car(String model) { this.model = model; this.color = "Blue"; this.price = 50000000; } public Car(String model, String color) { this.model = model; this.color = color; this.price = 50000000; } public Car(String model, String color, double price) { this.model = model; this.color = color; this.price = price; }public Car(String model) { //(1) this(model, "Blue", 50000000); } public Car(String model, String color) { //(2) this(model, color, 100000000); } public Car(String model, String color, double price) { //(3) this.model = model; this.color = color; this.price = price; }