-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
임준형/java-basic/src/main/java/week3/poly/ex2/AnimalSoundMain2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("동물 소리 테스트 종료"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
임준형/java-basic/src/main/java/week3/poly/ex2/AnimalSoundMain3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("동물 소리 테스트 종료"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package week3.poly.ex2; | ||
|
||
public class Pig { | ||
} |