From b160ce581c446e1b4e35c704dec62bc145538792 Mon Sep 17 00:00:00 2001 From: arinming Date: Tue, 6 Feb 2024 02:54:18 +0900 Subject: [PATCH] =?UTF-8?q?[Week3][Chap11]=20=EC=B6=94=EC=83=81=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A42=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/poly/ex4/AbstractAnimal.java" | 8 +++++ .../src/poly/ex4/AbstractMain.java" | 33 +++++++++++++++++++ .../java-basic/src/poly/ex4/Cat.java" | 13 ++++++++ .../java-basic/src/poly/ex4/Caw.java" | 13 ++++++++ .../java-basic/src/poly/ex4/Dog.java" | 13 ++++++++ 5 files changed, 80 insertions(+) create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/AbstractAnimal.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/AbstractMain.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Cat.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Caw.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Dog.java" diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/AbstractAnimal.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/AbstractAnimal.java" new file mode 100644 index 0000000..56cb20f --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/AbstractAnimal.java" @@ -0,0 +1,8 @@ +package poly.ex4; + +public abstract class AbstractAnimal { + + // 순수 추상 클래스 + public abstract void sound(); + public abstract void move(); +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/AbstractMain.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/AbstractMain.java" new file mode 100644 index 0000000..fbab6cd --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/AbstractMain.java" @@ -0,0 +1,33 @@ +package poly.ex4; +public class AbstractMain { + public static void main(String[] args) { +// 추상클래스 생성 불가 +// AbstractAnimal animal = new AbstractAnimal(); + + Dog dog = new Dog(); + Cat cat = new Cat(); + Caw caw = new Caw(); + + soundAnimal(dog); + soundAnimal(cat); + soundAnimal(caw); + + moveAnimal(dog); + moveAnimal(cat); + moveAnimal(caw); + } + + // 변하지 않는 부분 + private static void soundAnimal(AbstractAnimal animal) { + System.out.println("동물 소리 테스트 시작"); + animal.sound(); + System.out.println("동물 소리 테스트 종료"); + } + + // 변하지 않는 부분 + private static void moveAnimal(AbstractAnimal animal) { + System.out.println("동물 이동 테스트 시작"); + animal.move(); + System.out.println("동물 이동 테스트 종료"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Cat.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Cat.java" new file mode 100644 index 0000000..f7a5ca1 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Cat.java" @@ -0,0 +1,13 @@ +package poly.ex4; + +public class Cat extends AbstractAnimal { + @Override + public void sound() { + System.out.println("냐옹"); + } + + @Override + public void move() { + System.out.println("고양이 이동"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Caw.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Caw.java" new file mode 100644 index 0000000..f8b441b --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Caw.java" @@ -0,0 +1,13 @@ +package poly.ex4; + +public class Caw extends AbstractAnimal { + @Override + public void sound() { + System.out.println("음메"); + } + + @Override + public void move() { + System.out.println("소 이동"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Dog.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Dog.java" new file mode 100644 index 0000000..4125495 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex4/Dog.java" @@ -0,0 +1,13 @@ +package poly.ex4; + +public class Dog extends AbstractAnimal { + @Override + public void sound() { + System.out.println("멍멍"); + } + + @Override + public void move() { + System.out.println("개 이동"); + } +}