03. JAVA/기초

17. 자바 8 (JAVA 8) - 인터페이스 default 메소드 정의하기

THE HEYDAZE 2021. 7. 7. 16:05
  OS   Windows 10 PRO 64bit 버전 20H2 (OS 빌드 19042.867)
  JAVA   8

 

[interface] TestInterface1
public interface TestInterface1 {

    default void show() {
        System.out.println("Interface 1");
    }

    static void hello() {
        System.out.println("Hello World");
    }
}

 

[interface] TestInterface2
public interface TestInterface2 {

    default void show() {
        System.out.println("Interface 2");
    }
}

 

[class] Client
public class Client implements TestInterface1, TestInterface2{

    @Override
    public void show() {
        TestInterface1.super.show();
        TestInterface2.super.show();
        TestInterface1.hello();
    }

    public static void main(String[] args) {
        Client client = new Client();
        client.show();
    }
}

 

결과