-
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
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
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,7 @@ | ||
package week3.poly.ex2; | ||
|
||
public class Animal { | ||
public void sound() { | ||
System.out.println("동물 울음 소리"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
임준형/java-basic/src/main/java/week3/poly/ex2/AnimalSoundMain1.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,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<Animal> 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("동물 소리 테스트 종료"); | ||
} | ||
} |
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,9 @@ | ||
package week3.poly.ex2; | ||
|
||
public class Cat extends Animal { | ||
|
||
@Override | ||
public void 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,8 @@ | ||
package week3.poly.ex2; | ||
|
||
public class Caw extends Animal{ | ||
@Override | ||
public void 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,8 @@ | ||
package week3.poly.ex2; | ||
|
||
public class Dog extends Animal{ | ||
@Override | ||
public void sound() { | ||
System.out.println("멍멍"); | ||
} | ||
} |