From 7f17c1456bf06b4c48427c2480c2905c49330118 Mon Sep 17 00:00:00 2001 From: toychip Date: Wed, 14 Feb 2024 00:53:37 +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(#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/week3/poly/ex5/diamond/Child.java" | 2 +- .../week3/poly/ex5/diamond/DiamondMain.java" | 2 +- .../week3/poly/ex5/diamond/InterfaceA.java" | 2 +- .../week3/poly/ex5/diamond/InterfaceB.java" | 2 +- .../java/week3/poly/ex6/AbstractAnimal.java" | 9 ++++++ .../src/main/java/week3/poly/ex6/Bird.java" | 13 ++++++++ .../main/java/week3/poly/ex6/Chicken.java" | 13 ++++++++ .../src/main/java/week3/poly/ex6/Dog.java" | 8 +++++ .../src/main/java/week3/poly/ex6/Fly.java" | 5 +++ .../java/week3/poly/ex6/SoundFlyMain.java" | 32 +++++++++++++++++++ 10 files changed, 84 insertions(+), 4 deletions(-) rename "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/Child.java" => "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/Child.java" (91%) rename "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/DiamondMain.java" => "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/DiamondMain.java" (88%) rename "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/InterfaceA.java" => "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/InterfaceA.java" (70%) rename "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/InterfaceB.java" => "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/InterfaceB.java" (70%) create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/AbstractAnimal.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Bird.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Chicken.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Dog.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Fly.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/SoundFlyMain.java" diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/Child.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/Child.java" similarity index 91% rename from "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/Child.java" rename to "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/Child.java" index e8e1100..ac90911 100644 --- "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/Child.java" +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/Child.java" @@ -1,4 +1,4 @@ -package week3.poly.diamond; +package week3.poly.ex5.diamond; public class Child implements InterfaceA, InterfaceB{ @Override diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/DiamondMain.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/DiamondMain.java" similarity index 88% rename from "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/DiamondMain.java" rename to "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/DiamondMain.java" index 0761549..ddfff39 100644 --- "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/DiamondMain.java" +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/DiamondMain.java" @@ -1,4 +1,4 @@ -package week3.poly.diamond; +package week3.poly.ex5.diamond; public class DiamondMain { public static void main(String[] args) { diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/InterfaceA.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/InterfaceA.java" similarity index 70% rename from "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/InterfaceA.java" rename to "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/InterfaceA.java" index c9c75a5..8bc7ca6 100644 --- "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/InterfaceA.java" +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/InterfaceA.java" @@ -1,4 +1,4 @@ -package week3.poly.diamond; +package week3.poly.ex5.diamond; public interface InterfaceA { void methodA(); diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/InterfaceB.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/InterfaceB.java" similarity index 70% rename from "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/InterfaceB.java" rename to "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/InterfaceB.java" index 993c230..a2f9bbc 100644 --- "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/diamond/InterfaceB.java" +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex5/diamond/InterfaceB.java" @@ -1,4 +1,4 @@ -package week3.poly.diamond; +package week3.poly.ex5.diamond; public interface InterfaceB { void methodB(); diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/AbstractAnimal.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/AbstractAnimal.java" new file mode 100644 index 0000000..7ed07e0 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/AbstractAnimal.java" @@ -0,0 +1,9 @@ +package week3.poly.ex6; + +public abstract class AbstractAnimal { + public abstract void sound(); + + public void move() { + System.out.println("동물이 이동합니다."); + } +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Bird.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Bird.java" new file mode 100644 index 0000000..9d24096 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Bird.java" @@ -0,0 +1,13 @@ +package week3.poly.ex6; + +public class Bird extends AbstractAnimal implements Fly { + @Override // AbstractAnimal + public void sound() { + System.out.println("짹짹"); + } + + @Override + public void fly() { + System.out.println("새 날기"); + } +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Chicken.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Chicken.java" new file mode 100644 index 0000000..95a9d39 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Chicken.java" @@ -0,0 +1,13 @@ +package week3.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/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Dog.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Dog.java" new file mode 100644 index 0000000..0b48818 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Dog.java" @@ -0,0 +1,8 @@ +package week3.poly.ex6; + +public class Dog extends AbstractAnimal { + @Override + public void sound() { + System.out.println("멍멍"); + } +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Fly.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Fly.java" new file mode 100644 index 0000000..b141b6b --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/Fly.java" @@ -0,0 +1,5 @@ +package week3.poly.ex6; + +public interface Fly { + void fly(); +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/SoundFlyMain.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/SoundFlyMain.java" new file mode 100644 index 0000000..67634e2 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex6/SoundFlyMain.java" @@ -0,0 +1,32 @@ +package week3.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 인터페이스가 있으면 사용 가능 + private static void flyAnimal(Fly fly) { + System.out.println("날기 테스트 시작"); + fly.fly(); + System.out.println("날기 테스트 종료"); + } + +}