From c840abbdab214999d521194df687bbe5c13cca0e Mon Sep 17 00:00:00 2001 From: arinming Date: Tue, 6 Feb 2024 14:08:33 +0900 Subject: [PATCH] =?UTF-8?q?[Week3][Chap11]=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EC=99=80=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=ED=99=9C=EC=9A=A9=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/poly/ex6/AbstractAnimal.java" | 9 ++++++ .../java-basic/src/poly/ex6/Bird.java" | 13 +++++++++ .../java-basic/src/poly/ex6/Chicken.java" | 13 +++++++++ .../java-basic/src/poly/ex6/Dog.java" | 8 +++++ .../java-basic/src/poly/ex6/Fly.java" | 5 ++++ .../src/poly/ex6/SoundFlyMain.java" | 29 +++++++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/AbstractAnimal.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Bird.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Chicken.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Dog.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Fly.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/SoundFlyMain.java" diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/AbstractAnimal.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/AbstractAnimal.java" new file mode 100644 index 0000000..cfa09cc --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/AbstractAnimal.java" @@ -0,0 +1,9 @@ +package poly.ex6; + +public abstract class AbstractAnimal { + public abstract void sound(); + + public void move() { + System.out.println("동물이 이동합니다."); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Bird.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Bird.java" new file mode 100644 index 0000000..3594c43 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Bird.java" @@ -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("새 날기"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Chicken.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Chicken.java" new file mode 100644 index 0000000..29a7632 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Chicken.java" @@ -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("닭 날기"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Dog.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Dog.java" new file mode 100644 index 0000000..a37eb82 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Dog.java" @@ -0,0 +1,8 @@ +package poly.ex6; + +public class Dog extends AbstractAnimal { + @Override + public void sound() { + System.out.println("멍멍"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Fly.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Fly.java" new file mode 100644 index 0000000..087a36e --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/Fly.java" @@ -0,0 +1,5 @@ +package poly.ex6; + +public interface Fly { + void fly(); +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/SoundFlyMain.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/SoundFlyMain.java" new file mode 100644 index 0000000..5428069 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex6/SoundFlyMain.java" @@ -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(); + } +}