로딩
요청 처리 중입니다...

내가 보려고 만든 디폴트 메서드와 static 메서드 - 코드 분석

 내가 보려고 만든 디폴트 메서드와 static 메서드 - 코드 분석

interface MyInterface{ // method()와 newMethod()는 추상메서드 void method(); void newMethod(); } interface MyInterface{ // method()는 추상메서드지만 newMethod()는 디폴트 메서드. void method(); default void newMethod() {} } 디폴트 메서드는 인터페이스에 추가되더라도, 인터페이스를 구현한 클래스를 수정할 필요가 없음. 반면, 인터페이스에 추상 메서드를 추가하면, 인터페이스를 구현한 클래스에서 추가한 추상 메서드도 구현해줘야 함.

예제 실험 코드 결과 class DefaultMethodTest { public static void main(String[] args) { Child c = new Child(); c.method1(); c.method2(); MyInterface.staticMethod(); MyInterface2.staticMethod();...