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 2d31b74 commit b160ce5
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 김아린/java-basic/src/poly/ex4/AbstractAnimal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package poly.ex4;

public abstract class AbstractAnimal {

// 순수 추상 클래스
public abstract void sound();
public abstract void move();
}
33 changes: 33 additions & 0 deletions 김아린/java-basic/src/poly/ex4/AbstractMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package poly.ex4;
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();

soundAnimal(dog);
soundAnimal(cat);
soundAnimal(caw);

moveAnimal(dog);
moveAnimal(cat);
moveAnimal(caw);
}

// 변하지 않는 부분
private static void soundAnimal(AbstractAnimal animal) {
System.out.println("동물 소리 테스트 시작");
animal.sound();
System.out.println("동물 소리 테스트 종료");
}

// 변하지 않는 부분
private static void moveAnimal(AbstractAnimal animal) {
System.out.println("동물 이동 테스트 시작");
animal.move();
System.out.println("동물 이동 테스트 종료");
}
}
13 changes: 13 additions & 0 deletions 김아린/java-basic/src/poly/ex4/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package poly.ex4;

public class Cat extends AbstractAnimal {
@Override
public void sound() {
System.out.println("냐옹");
}

@Override
public void move() {
System.out.println("고양이 이동");
}
}
13 changes: 13 additions & 0 deletions 김아린/java-basic/src/poly/ex4/Caw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package poly.ex4;

public class Caw extends AbstractAnimal {
@Override
public void sound() {
System.out.println("음메");
}

@Override
public void move() {
System.out.println("소 이동");
}
}
13 changes: 13 additions & 0 deletions 김아린/java-basic/src/poly/ex4/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package poly.ex4;

public class Dog extends AbstractAnimal {
@Override
public void sound() {
System.out.println("멍멍");
}

@Override
public void move() {
System.out.println("개 이동");
}
}

0 comments on commit b160ce5

Please sign in to comment.