Skip to content

Commit

Permalink
[Week3][Chap11] 다형성 활용3 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Feb 1, 2024
1 parent ac7be4b commit a8ae3fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 8 additions & 8 deletions 김아린/java-basic/src/poly/ex2/AnimalPolyMain1.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

public class AnimalPolyMain1 {
public static void main(String[] args) {
Animal dog = new Dog();
Cat cat = new Cat();
Animal caw = new Caw();
Duck duck = new Duck();
Animal a = new Animal();
a.sound();

soundAnimal(dog);
soundAnimal(cat);
soundAnimal(caw);
soundAnimal(duck);
Animal[] animalArr = {new Dog(), new Cat(), new Caw(), new Pig()};

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

// 변하지 않는 부분
private static void soundAnimal(Animal animal) {
System.out.println("동물 소리 테스트 시작");
animal.sound();
Expand Down
5 changes: 5 additions & 0 deletions 김아린/java-basic/src/poly/ex2/Pig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package poly.ex2;

public class Pig extends Animal {
// Todo sound 해야하는데..
}

0 comments on commit a8ae3fc

Please sign in to comment.