• 코드:
​x
 
1
abstract class Animal { abstract void cry(); }
2
​
3
class Cat extends Animal {
4
    void cry() {
5
        System.out.println("냐옹냐옹!");
6
    }
7
}
8
​
9
class Dog extends Animal {
10
    void cry() {
11
        System.out.println("멍멍!");
12
    }
13
}
14
​
15
public class prog {
16
    public static void main(String[] args) {
17
        // Animal a = new Animal(); // 추상 클래스는 인스턴스를 생성할 수 없음.
18
        Cat c = new Cat();
19
        Dog d = new Dog();
20
        
21
        c.cry();
22
        d.cry();
23
    }
24
}
표준입력 & 실행옵션