diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/AbstractAnimal.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/AbstractAnimal.java" new file mode 100644 index 0000000..bfaa559 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/AbstractAnimal.java" @@ -0,0 +1,10 @@ +package poly.ex3; + +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/ex3/AbstractMain.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/AbstractMain.java" new file mode 100644 index 0000000..d0b2e1b --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/AbstractMain.java" @@ -0,0 +1,28 @@ +package poly.ex3; + +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(); + Duck duck = new Duck(); + + cat.sound(); + cat.move(); + + soundAnimal(dog); + soundAnimal(cat); + soundAnimal(caw); + soundAnimal(duck); + } + + // 변하지 않는 부분 + private static void soundAnimal(AbstractAnimal animal) { + System.out.println("동물 소리 테스트 시작"); + animal.sound(); + System.out.println("동물 소리 테스트 종료"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Cat.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Cat.java" new file mode 100644 index 0000000..f14d518 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Cat.java" @@ -0,0 +1,8 @@ +package poly.ex3; + +public class Cat 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/ex3/Caw.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Caw.java" new file mode 100644 index 0000000..840ad60 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Caw.java" @@ -0,0 +1,8 @@ +package poly.ex3; + +public class Caw 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/ex3/Dog.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Dog.java" new file mode 100644 index 0000000..c1e968e --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Dog.java" @@ -0,0 +1,8 @@ +package poly.ex3; + +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/ex3/Duck.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Duck.java" new file mode 100644 index 0000000..f6f252e --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex3/Duck.java" @@ -0,0 +1,8 @@ +package poly.ex3; + +public class Duck extends AbstractAnimal { + @Override + public void sound() { + System.out.println("꽉꽉"); + } +}