-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package poly.ex6; | ||
|
||
public abstract class AbstractAnimal { | ||
public abstract void sound(); | ||
|
||
public void move() { | ||
System.out.println("동물이 이동합니다."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package poly.ex6; | ||
|
||
public class Bird extends AbstractAnimal implements Fly{ | ||
@Override | ||
public void sound() { | ||
System.out.println("짹짹"); | ||
} | ||
|
||
@Override | ||
public void fly() { | ||
System.out.println("새 날기"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package poly.ex6; | ||
|
||
public class Chicken extends AbstractAnimal implements Fly { | ||
@Override | ||
public void sound() { | ||
System.out.println("꼬끼오"); | ||
} | ||
|
||
@Override | ||
public void fly() { | ||
System.out.println("닭 날기"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package poly.ex6; | ||
|
||
public class Dog extends AbstractAnimal { | ||
@Override | ||
public void sound() { | ||
System.out.println("멍멍"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package poly.ex6; | ||
|
||
public interface Fly { | ||
void fly(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package poly.ex6; | ||
|
||
public class SoundFlyMain { | ||
public static void main(String[] args) { | ||
Dog dog = new Dog(); | ||
Bird bird = new Bird(); | ||
Chicken chicken = new Chicken(); | ||
|
||
soundAnimal(dog); | ||
soundAnimal(bird); | ||
soundAnimal(chicken); | ||
|
||
flyAnimal(bird); | ||
flyAnimal(chicken); | ||
} | ||
|
||
// AbstractAnimal 사용 가능 | ||
private static void soundAnimal(AbstractAnimal animal) { | ||
System.out.println("동물 소리 테스트 시작"); | ||
animal.sound(); | ||
System.out.println("동물 소리 테스트 종료"); | ||
} | ||
|
||
// Fly 인터페이스가 있으면 사용 가능 | ||
public static void flyAnimal(Fly fly) { | ||
System.out.println("날기 테스트 시작"); | ||
fly.fly(); | ||
} | ||
} |