• 코드:
​x
 
1
class Car {
2
    private String modelName;
3
    private int modelYear;
4
    private String color;
5
    private int maxSpeed;
6
    
7
    Car(String modelName, int modelYear, String color, int maxSpeed) {
8
        this.modelName = modelName;
9
        this.modelYear = modelYear;
10
        this.color = color;
11
        this.maxSpeed = maxSpeed;
12
    }
13
    
14
    Car() {
15
        this("아반떼", 2016, "흰색", 200);
16
    }
17
    
18
    public String getModel() {
19
        return this.modelYear + "년식 " + this.modelName + " " + this.color;
20
    }
21
}
22
​
23
public class prog {
24
    public static void main(String[] args) {
25
        Car car01 = new Car();
26
        Car car02 = new Car();
27
        
28
        System.out.println(car01.toString());
29
        System.out.println(car02.toString());
30
    }
31
}
표준입력 & 실행옵션