public abstract class Car {
public abstract void drive();
public abstract void stop();
public abstract void start();
public abstract void turnoff();
final public void run()
{
start();
drive();
stop();
turnoff();
}
}
public class Avante extends Car{
@Override
public void drive() {
// TODO Auto-generated method stub
System.out.println("아반타 주행시작");
}
@Override
public void stop() {
// TODO Auto-generated method stub
System.out.println("아반타 정지");
}
@Override
public void start() {
// TODO Auto-generated method stub
System.out.println("아반타 시동");
}
@Override
public void turnoff() {
// TODO Auto-generated method stub
System.out.println("아반타 시동해제");
}
}
public class Genesis extends Car{
@Override
public void drive() {
// TODO Auto-generated method stub
System.out.println("제네시스 주행시작");
}
@Override
public void stop() {
// TODO Auto-generated method stub
System.out.println("제네시스 정지");
}
@Override
public void start() {
// TODO Auto-generated method stub
System.out.println("제네시스 시동");
}
@Override
public void turnoff() {
// TODO Auto-generated method stub
System.out.println("제네시스 시동해제");
}
}
public class Genesis extends Car{
@Override
public void drive() {
// TODO Auto-generated method stub
System.out.println("제네시스 주행시작");
}
@Override
public void stop() {
// TODO Auto-generated method stub
System.out.println("제네시스 정지");
}
@Override
public void start() {
// TODO Auto-generated method stub
System.out.println("제네시스 시동");
}
@Override
public void turnoff() {
// TODO Auto-generated method stub
System.out.println("제네시스 시동해제");
}
}
public class Sonata extends Car{
@Override
public void drive() {
// TODO Auto-generated method stub
System.out.println("소나타 주행시작");
}
@Override
public void stop() {
// TODO Auto-generated method stub
System.out.println("소나타 정지");
}
@Override
public void start() {
// TODO Auto-generated method stub
System.out.println("소나타 시동");
}
@Override
public void turnoff() {
// TODO Auto-generated method stub
System.out.println("소나타 시동해제");
}
}
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList list = new ArrayList<>();
list.add(new Avante());
list.add(new Genesis());
list.add(new Grandeur());
list.add(new Sonata());
for(Car c : list)
{
c.run();
}
}
}
'Java' 카테고리의 다른 글
인터페이스 & 추상 클래스 (0) | 2019.10.28 |
---|---|
자바 연습 (상속& 업캐스팅) (0) | 2019.10.27 |
final 키워드 사용 (0) | 2019.10.27 |
추상 클래스 & 추상 메소드 (0) | 2019.10.27 |
down casting & instanceof (0) | 2019.10.27 |