Skip to content

Commit

Permalink
[Week3][Chap11] 클래스와 인터페이스 활용 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
toychip committed Feb 13, 2024
1 parent e559f4f commit 7f17c14
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.poly.diamond;
package week3.poly.ex5.diamond;

public class Child implements InterfaceA, InterfaceB{
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.poly.diamond;
package week3.poly.ex5.diamond;

public class DiamondMain {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.poly.diamond;
package week3.poly.ex5.diamond;

public interface InterfaceA {
void methodA();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.poly.diamond;
package week3.poly.ex5.diamond;

public interface InterfaceB {
void methodB();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package week3.poly.ex6;

public abstract class AbstractAnimal {
public abstract void sound();

public void move() {
System.out.println("동물이 이동합니다.");
}
}
13 changes: 13 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex6/Bird.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package week3.poly.ex6;

public class Bird extends AbstractAnimal implements Fly {
@Override // AbstractAnimal
public void sound() {
System.out.println("짹짹");
}

@Override
public void fly() {
System.out.println("새 날기");
}
}
13 changes: 13 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex6/Chicken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package week3.poly.ex6;

public class Chicken extends AbstractAnimal implements Fly {
@Override
public void sound() {
System.out.println("꼬기오");
}

@Override
public void fly() {
System.out.println("닭 날기");
}
}
8 changes: 8 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/ex6/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package week3.poly.ex6;

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

public interface Fly {
void fly();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package week3.poly.ex6;

public class SoundFlyMain {

public static void main(String[] args) {
Dog dog = new Dog();
Bird bird = new Bird();
Chicken chicken = new Chicken();

soundAnimal(dog);
soundAnimal(bird);
soundAnimal(chicken);

flyAnimal(bird);
flyAnimal(chicken);
}

//AbstractAnimal 사용 가능
private static void soundAnimal(AbstractAnimal animal) {
System.out.println("동물 소리 테스트 시작");
animal.sound();
System.out.println("동물 소리 테스트 종료");
}

//Fly 인터페이스가 있으면 사용 가능
private static void flyAnimal(Fly fly) {
System.out.println("날기 테스트 시작");
fly.fly();
System.out.println("날기 테스트 종료");
}

}

0 comments on commit 7f17c14

Please sign in to comment.