[ 작업 환경 ]

 

Windows10

jdk-15

 

 

 

 

 

1. FlyingAnimal.java 작성

 

public abstract class FlyingAnimal {
    protected String name;

    public FlyingAnimal(String myname) {
        this.name = myname;
    }

    abstract void fly();
}

 

 

 

 

 

2. Hawk.java 작성

 

public class Hawk extends FlyingAnimal {
    
    Hawk(String myname) {
        super(myname);
    }
    
    void fly() {
        System.out.println("Hawk(" + name + ") flies");
    }
}

 

 

 

 

 

3. Dove.java 작성

 

public class Dove extends FlyingAnimal {

    Dove(String myname) {
        super(myname);
    }

    void fly() {
        System.out.println("Dove(" + name + ") flies");
    }
}

 

 

 

 

 

4. MyTester3.java 작성

 

public class MyTester3 {
    public static void main(String[] args) {
        Hawk myhawk = new Hawk("Kildong");
        myhawk.fly();
        Dove mydove = new Dove("Choo");
        mydove.fly();
    }
}

 

 

 

 

 

5. 소스코드 실행

 

javac FlyingAnimal.java
javac Hawk.java
javac Dove.java
javac MyTester3.java
java MyTester3

 

 

 

 

 

+ Recent posts