diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Animal.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Animal.java" new file mode 100644 index 0000000..fa59b4a --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Animal.java" @@ -0,0 +1,7 @@ +package week3.poly.ex2; + +public class Animal { + 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/ex2/AnimalSoundMain1.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/AnimalSoundMain1.java" new file mode 100644 index 0000000..fce9ac5 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/AnimalSoundMain1.java" @@ -0,0 +1,35 @@ +package week3.poly.ex2; + +import java.util.ArrayList; +import java.util.List; + +public class AnimalSoundMain1 { + public static void main(String[] args) { + Dog dog = new Dog(); + Cat cat = new Cat(); + Caw caw = new Caw(); + + soundAnimal(dog); + soundAnimal(cat); + soundAnimal(caw); + + // 혼자해본 연습 + /* + Animal dog1 = new Dog(); + Animal cat1 = new Cat(); + Animal caw1 = new Caw(); + List animals = new ArrayList<>(); + animals.add(dog1); + animals.add(cat1); + animals.add(caw1); + + animals.forEach(animal -> soundAnimal(animal)); + */ + } + + private static void soundAnimal(Animal animal) { + System.out.println("동물 소리 테스트 시작"); + animal.sound(); + System.out.println("동물 소리 테스트 종료"); + } +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Cat.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Cat.java" new file mode 100644 index 0000000..da2235c --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Cat.java" @@ -0,0 +1,9 @@ +package week3.poly.ex2; + +public class Cat extends Animal { + + @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/ex2/Caw.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Caw.java" new file mode 100644 index 0000000..a7e2b6d --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Caw.java" @@ -0,0 +1,8 @@ +package week3.poly.ex2; + +public class Caw extends Animal{ + @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/ex2/Dog.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Dog.java" new file mode 100644 index 0000000..71adaaa --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/ex2/Dog.java" @@ -0,0 +1,8 @@ +package week3.poly.ex2; + +public class Dog extends Animal{ + @Override + public void sound() { + System.out.println("멍멍"); + } +}