java - 상속 예제, 같은 명령문은 상속으로 묶기

imjingu·2023년 8월 21일
0

개발공부

목록 보기
398/481
package chapter20230821.test01;

class Vehicle {
	int speed;
	int heading; // 방향
	
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	
	public void turn(int angle) {
		heading = angle;
	}
}

class Car extends Vehicle {
	int price;
}

class Truck extends Vehicle {
	int payload;
}

class Bus extends Vehicle {
	int seats;
}
public class test_Vehicle {

	public static void main(String[] args) {
		Car car = new Car();
		Truck truck = new Truck();
		Bus bus = new Bus();
		
		car.setSpeed(10);

	}

}

0개의 댓글