Skip to content

Commit

Permalink
[Week3][Chap11] 추상 클래스2 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
toychip committed Feb 13, 2024
1 parent 5e380a0 commit 6a81e7c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package week3.poly.ex4;

public abstract class AbstractAnimal {

public abstract void sound();
public abstract void move();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package week3.poly.ex4;

public class AbstractMain {

public static void main(String[] args) {
Dog dog = new Dog();
Cat cat = new Cat();
Caw caw = new Caw();

cat.sound();
cat.move();

soundAnimal(dog);
moveAnimal(dog);

soundAnimal(cat);
moveAnimal(cat);

soundAnimal(caw);
moveAnimal(caw);
}

private static void soundAnimal(AbstractAnimal animal) {
System.out.println("테스트 시작");
animal.sound();
System.out.println("테스트 종료");
}

private static void moveAnimal(AbstractAnimal animal) {
animal.move();
}
}
14 changes: 14 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex4/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package week3.poly.ex4;

public class Cat extends AbstractAnimal {

@Override
public void sound() {
System.out.println("야옹");
}

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


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

@Override
public void move() {
System.out.println("소 이동");
}
}
14 changes: 14 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex4/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package week3.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 6a81e7c

Please sign in to comment.