https://standout.tistory.com/100
클래스와 인터페이스의 구성
앞서 클래스와 인터페이스의 차이를 간단히 확인해봤다. 이제 클래스와 인터페이스의 구성하는 각각의 요소를 확인해보자. https://standout.tistory.com/85 JAVA Interface, 인터페이스 Class와의 차이 인터
standout.tistory.com
https://standout.tistory.com/85
JAVA Interface, 인터페이스 Class와의 차이
인터페이스는 계약서, 클래스는 개발팀이라 상상해보자. 인터페이스 클래스의 일종으로, 메서드의 내용은 구현하지 않는다 *클래스에게 지시해 구현(implement)시키는 계약서와 같은 역할으로 스
standout.tistory.com
interface는 일종의 계약서로,
무언가를 실행하거나 구현할 순 없지만 지시하는 역할이라고 하겠다.
원래 메서드가 구현될 수 없지만 추상/디폴트/정적/프라이빗 메서드는 가능하다.
public interface MyInterface {
// 추상 메서드
void myAbstractMethod();
// 디폴트 메서드
default void myDefaultMethod() {
System.out.println("This is a default method.");
}
// 정적 메서드
static void myStaticMethod() {
System.out.println("This is a static method.");
}
// 프라이빗 메서드 (Java 9 이상)
private void myPrivateMethod() {
System.out.println("This is a private method.");
}
// Java 9 이상에서는 private 인터페이스 메서드를 사용하여 추상/디폴트/정적 메서드 구현을 재사용할 수 있습니다.
private void myPrivateMethodHelper() {
System.out.println("This is a private method helper.");
}
// Java 9 이상에서는 private 인터페이스 메서드를 사용하여 추상 메서드 구현을 재사용할 수 있습니다.
private String myAbstractMethodHelper() {
return "This is a string from a private helper method.";
}
}
'JAVA' 카테고리의 다른 글
Java EE란? (0) | 2023.03.17 |
---|---|
문자열 포맷 형식 format(%/)을 이용한, 환율계산기 (2) | 2023.03.16 |
상속받다, extends와 implements의 차이 (0) | 2023.03.16 |
상속받다, implements (0) | 2023.03.16 |
덮어쓰는 annotation, @Override (0) | 2023.03.16 |