[JAVA] 49. 추상클래스 & 인터페이스 (2)인터페이스

서회정's avatar
Feb 17, 2025

[JAVA] 49. 추상클래스 & 인터페이스 (2)인터페이스

💡
인터페이스
interface 키워드를 통해 선언할 수 있다.
implements 키워드를 통해 일반 클래스에서 인터페이스를 구현할 수 있다.
package ex07.ch01; /* 삼성 리모컨, 엘지 리모컨 기능 : on, off */ interface Remocon { //interface는 원래 메모리에 띄울 수 없어서 new 없음 public abstract void on(); //public abstract 생략가능 void off(); } class SamsungRemocon implements Remocon { public void on() { System.out.println("삼성 리모컨 ON"); } public void off() { System.out.println("삼성 리모컨 OFF"); } } class LGRemocon implements Remocon { public void on() { System.out.println("엘지 리모컨 ON"); } public void off() { System.out.println("엘지 리모컨 OFF"); } } public class Inter01 { static void start(Remocon r) { r.on(); } public static void main(String[] args) { LGRemocon lg = new LGRemocon(); start(lg); } }
Share article

clubnerdy