Tesla 클래스에 인터페이스 구현하기
Tesla 클래스에 자율 주행 기능을 추가하려면 ElectricCar 인터페이스를 사용해 이 기능을 활성화해야 합니다. Tesla 클래스에서 인터페이스를 채택하고, 요구사항으로서 자율 주행 메서드를 구현해 보세요.
NOTE: 인터페이스의 void가 아닌 메서드는 해당 인터페이스를 구현하는 클래스에서 반드시 구현해야 합니다.
이 연습은 강의의 일부입니다
Java로 배우는 객체 지향 프로그래밍 입문
연습 안내
Tesla클래스에서implements키워드를 사용해ElectricCar인터페이스를 구현하세요.Tesla클래스 안에public접근 제한자로voidactivateSelfDriving메서드를 구현하고, 호출 시"self driving on"을 출력하게 하세요.myTesla객체 인스턴스에서activateSelfDriving메서드를 호출하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
public class Main {
interface ElectricCar {
void activateSelfDriving();
}
// Implement ElectricCar Interface
static class Tesla ____ ____ {
// Implement activateSelfDriving method
public void ____() {
System.out.____("self driving on");
}
}
public static void main(String[] args) {
Tesla myTesla = new Tesla();
// Call activateSelfDriving method
____.____();
}
}