인터페이스의 default 메서드 실습
문제 Taxi 클래스는 Meter 인터페이스를 구현합니다. TaxiExam 클래스를 실행했을 때 실행결과와 같은 결과가 나올 수 있도록 Meter 인터페이스를 수정해주세요. Taxi 클래스와 TaxiExam 클래스는 수정하지 마세요.
package javaStudy;
public interface Meter{
public void start();
public int stop(int distance);
_____________________________________
_____________________________________
_____________________________________
}
package javaStudy;
public class Taxi implements Meter{
public void start() {
System.out.println("운행을 시작합니다.");
}
public int BASE_FARE = 3000;
public int stop(int distance) {
int fare = BASE_FARE + distance * 2;
System.out.println("운행을 종료합니다. 요금은 " + fare + "원입니다.");
return fare;
}
}
package javaStudy;
public class TaxiExam{
public static void main(String[] args) {
Taxi taxi = new Taxi();
taxi.start();
taxi.afterMidnight();
taxi.stop(10);
}
}
실행결과
운행을 시작합니다. 자정이 넘었습니다. 할증이 필요한 경우 이 메서드를 오버라이드하세요. 운행을 종료합니다. 요금은 3020원입니다.