존재 이유
- 인터페이스에 메서드를 추가하는 경우는 인터페이스를 구현하는 모든 클래스들이 추가된 매서드를 구현해야 하기 때문에 매우 해야할 일이 늘어나기 때문에
default 메서드
- 작성 :
public default void methos1(){}- 추상메서드 대신 default 메서드를 선언하면 인터페이스를 구현한 클래스들이 추상메서드처럼 구현을 할 필요하가 없다.
사용 예시
class Main{ public static void main(String[] args) { Myinterface.static_method(); child c = new child(); c.default_method(); } } interface Myinterface{ static void static_method(){ System.out.println("Myinterface static method"); } default void default_method(){ System.out.println("Default method"); } } class child implements Myinterface{ }