• 코드:
​x
 
1
class Car {
2
    private String modelName;
3
    private int modelYear;
4
    private String color;
5
    private int maxSpeed;
6
    private int currentSpeed;
7
    
8
    Car(String modelName, int modelYear, String color, int maxSpeed) {
9
        this.modelName = modelName;
10
        this.modelYear = modelYear;
11
        this.color = color;
12
        this.maxSpeed = maxSpeed;
13
        this.currentSpeed = 0;
14
    }
15
    
16
    Car() {
17
        this("소나타", 2012, "검정색", 160);  // 다른 생성자를 호출함.
18
    }
19
    
20
    public String getModel() {
21
        return this.modelYear + "년식 " + this.modelName + " " + this.color;
22
    }
23
}
24
​
25
public class prog {
26
    public static void main(String[] args) {
27
        Car tcpCar = new Car();
28
        System.out.println(tcpCar.getModel());
29
    }
30
}
표준입력 & 실행옵션