자바 키워드 implements

Jmnote (토론 | 기여)님의 2023년 5월 18일 (목) 10:52 판 (→‎예시 2)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

implements
임플리먼츠, 임플러먼츠 [ímpləmənts]

2 예시 1[ | ]

interface Animal {
  public void animalSound();
}
class Duck implements Animal {
    public void animalSound() {
        System.out.println("Quack");
    }
}
public class App {
    public static void main(String[] args) {
        Animal a = new Duck();
        a.animalSound();
    }
}

3 예시 2[ | ]

interface Animal {
    public void animalSound();
    public void sleep();
}
class Dog implements Animal {
    public void animalSound() {
        System.out.println("bark");
    }
    public void sleep() {
        System.out.println("zzz");
    }
}
public class App {
    public static void main(String args[]) {
        Animal d = new Dog();
        d.animalSound();
        d.sleep();
    }
}

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}