[추상 클래스]

“추상 클래스 정의”

public class Vehicle {

	private int curX, curY;
	
	public void reportPosition() {
		System.out.printf("차종: %s: 현재위치: (%d, %d)", this.getClass().getSimpleName(), curX, this.curY);
	}
	
	public void addFuel() {
		System.out.println("어떻게든 연료는 필요!");
	}
}
// TODO: Vehicle을 상속받는 구조로 변경해보자.
 public class ElectricCar extends Vehicle{
	 
	@Override 
    public void addFuel() {
        System.out.printf("차종: %s: 연료 주입: %s%n", this.getClass().getSimpleName(), "충전");
    }
}
// TODO: Vehicle을 상속받는 구조로 변경해보자.
 public class DieselSUV extends Vehicle{

	@Override 
    public void addFuel() {
        System.out.printf("차종: %s: 연료 주입: %s%n", this.getClass().getSimpleName(), "경유");
    }
}

“추상 클래스의 특징”

“추상 클래스를 사용하는 이유”

Untitled


[인터페이스]