-
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
6 changed files
with
70 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,10 @@ | ||
package poly.ex3; | ||
|
||
public abstract class AbstractAnimal { | ||
|
||
public abstract void sound(); | ||
|
||
public void move() { | ||
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,28 @@ | ||
package poly.ex3; | ||
|
||
public class AbstractMain { | ||
public static void main(String[] args) { | ||
// 추상클래스 생성 불가 | ||
// AbstractAnimal animal = new AbstractAnimal(); | ||
|
||
Dog dog = new Dog(); | ||
Cat cat = new Cat(); | ||
Caw caw = new Caw(); | ||
Duck duck = new Duck(); | ||
|
||
cat.sound(); | ||
cat.move(); | ||
|
||
soundAnimal(dog); | ||
soundAnimal(cat); | ||
soundAnimal(caw); | ||
soundAnimal(duck); | ||
} | ||
|
||
// 변하지 않는 부분 | ||
private static void soundAnimal(AbstractAnimal 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,8 @@ | ||
package poly.ex3; | ||
|
||
public class Cat extends AbstractAnimal{ | ||
@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 poly.ex3; | ||
|
||
public class Caw extends AbstractAnimal{ | ||
@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 poly.ex3; | ||
|
||
public class Dog extends AbstractAnimal { | ||
@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 poly.ex3; | ||
|
||
public class Duck extends AbstractAnimal { | ||
@Override | ||
public void sound() { | ||
System.out.println("꽉꽉"); | ||
} | ||
} |