Class를 상속받을때 extends를 사용하지만
Interface는 implements라는 예약어를 사용한다.
https://standout.tistory.com/157
상속받다, extends
상속받다, extends 상속 extends 확장하다 이미 작성된 클래스를 기반으로 새로운 클래스를 작성하고 확장할 수 있다. 이때 extends한 하위클래스 호출시, 상위클래스가 호출된 이후 상속받은 하위클
standout.tistory.com
Interface는,
실제 구현은 하지 않은 추상적인 클래스이다.
계약서라고 보면 되겠다.
https://standout.tistory.com/85
JAVA Interface, 인터페이스 Class와의 차이
인터페이스는 계약서, 클래스는 개발팀이라 상상해보자. 인터페이스 클래스의 일종으로, 메서드의 내용은 구현하지 않는다 *클래스에게 지시해 구현(implement)시키는 계약서와 같은 역할으로 스
standout.tistory.com
아래와 같이 Car는
implements를 통해 인터페이스를 상속받아
Venhicle 인터페이스의 메서드를 수행할 수 있다.
public interface Vehicle {
void start();
void stop();
}
public class Car implements Vehicle {
@Override
public void start() {
System.out.println("Car starts");
}
@Override
public void stop() {
System.out.println("Car stops");
}
}
'JAVA' 카테고리의 다른 글
계약서, interface (0) | 2023.03.16 |
---|---|
상속받다, extends와 implements의 차이 (0) | 2023.03.16 |
덮어쓰는 annotation, @Override (0) | 2023.03.16 |
Class 형변환 (0) | 2023.03.16 |
this 와 super (0) | 2023.03.16 |