• 코드:
​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
    {   // 인스턴스 초기화 블록
9
        this.currentSpeed = 0;
10
    }
11
    
12
    Car() {}
13
    Car(String modelName, int modelYear, String color, int maxSpeed) {
14
        this.modelName = modelName;
15
        this.modelYear = modelYear;
16
        this.color = color;
17
        this.maxSpeed = maxSpeed;
18
    }
19
    
20
    public int getSpeed() {
21
        return currentSpeed;
22
    }
23
}
24
​
25
public class prog {
26
    public static void main(String[] args) {
27
        Car myCar = new Car();                  // 인스턴스 생성
28
        System.out.println(myCar.getSpeed());   // 인스턴스 메소드의 호출
29
    }
30
}
표준입력 & 실행옵션