Skip to content

Commit

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

public abstract class AbstractAnimal {

public abstract void sound();
public void move(){
System.out.println("동물이 움직입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package week3.poly.ex3;

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);
soundAnimal(cat);
soundAnimal(caw);
}

private static void soundAnimal(AbstractAnimal animal) {
System.out.println("테스트 시작");
animal.sound();
System.out.println("테스트 종료");
}
}
9 changes: 9 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex3/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package week3.poly.ex3;

public class Cat extends AbstractAnimal {

@Override
public void sound() {
System.out.println("야옹");
}
}
9 changes: 9 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex3/Caw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package week3.poly.ex3;


public class Caw extends AbstractAnimal {
@Override
public void sound() {
System.out.println("음메");
}
}
9 changes: 9 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex3/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package week3.poly.ex3;


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

0 comments on commit 5e380a0

Please sign in to comment.