Skip to content

Commit

Permalink
[Week3][Chap11] 다형성 활용3 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
toychip committed Feb 13, 2024
1 parent 26b88e8 commit 108dd7e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package week3.poly.ex2;

public class AnimalSoundMain2 {
public static void main(String[] args) {
Dog dog = new Dog();
Cat cat = new Cat();
Caw caw = new Caw();

Animal[] animals = {dog, cat, caw};

for (Animal animal : animals) {
soundAnimal(animal);
}
}

private static void soundAnimal(Animal animal) {
System.out.println("동물 소리 테스트 시작");
animal.sound();
System.out.println("동물 소리 테스트 종료");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package week3.poly.ex2;

import java.util.Arrays;

public class AnimalSoundMain3 {
public static void main(String[] args) {
Animal[] animals = {new Dog(), new Cat(), new Caw()};

Arrays.stream(animals).toList().forEach(AnimalSoundMain3::soundAnimal);
}

private static void soundAnimal(Animal animal) {
System.out.println("동물 소리 테스트 시작");
animal.sound();
System.out.println("동물 소리 테스트 종료");
}
}
4 changes: 4 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex2/Pig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package week3.poly.ex2;

public class Pig {
}

0 comments on commit 108dd7e

Please sign in to comment.