Skip to content

Commit

Permalink
[Week3][Chap11] 추상 클래스2 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Feb 5, 2024
1 parent a8ae3fc commit 2d31b74
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 김아린/java-basic/src/poly/ex3/AbstractAnimal.java
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("동물이 움직입니다.");
}
}
28 changes: 28 additions & 0 deletions 김아린/java-basic/src/poly/ex3/AbstractMain.java
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("동물 소리 테스트 종료");
}
}
8 changes: 8 additions & 0 deletions 김아린/java-basic/src/poly/ex3/Cat.java
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("냐옹");
}
}
8 changes: 8 additions & 0 deletions 김아린/java-basic/src/poly/ex3/Caw.java
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("음메");
}
}
8 changes: 8 additions & 0 deletions 김아린/java-basic/src/poly/ex3/Dog.java
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("멍멍");
}
}
8 changes: 8 additions & 0 deletions 김아린/java-basic/src/poly/ex3/Duck.java
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("꽉꽉");
}
}

0 comments on commit 2d31b74

Please sign in to comment.