[java] 인터페이스를 활용한 객체 지향 프로그래밍의 예시는?

자바에서는 Runnable 인터페이스가 대표적인 예입니다. Runnablerun 메서드를 정의하고, 해당 인터페이스를 구현한 클래스는 run 메서드 내에서 원하는 작업을 정의할 수 있습니다.

public class Example implements Runnable {
    public void run() {
        System.out.println("This is an example of using interfaces in object-oriented programming.");
    }

    public static void main(String[] args) {
        Example example = new Example();
        Thread thread = new Thread(example);
        thread.start();
    }
}

이 예시에서는 Example 클래스가 Runnable 인터페이스를 구현하고, run 메서드를 재정의하여 스레드에서 실행될 작업을 정의합니다.

참고 문헌: