YOO
Published 2022. 6. 7. 20:31
목표달성(2022.6.7) 구디아카데미

■ HOMEWORK
[트러블슈팅] 그날 트러블슈팅 또는 본인 습관체크 >> 
▶ 어떤게 업캐스팅인지 다운캐스팅인지 형변환 생략 가능 불가능은 잘 판단하게 되었다.
▶ 타이어문제는 조금 어려운편이어서 복습이많이 필요할 것 같다....
▶ 


■ 목표달성
1. 다형성을 이용하여 다음을 설명할수 있다.
   ---------------------------------------------------------------
   1. 상속도 확인
       Vehicle : run()차량이 달립니다. (-----)
      ↑          ↑         
      Bus           Taxi  
   run()버스가 달립니다.    run()택시가 달립니다.        >>>>  ##### Q1) Bus, Taxi 클래스를 구현하시오.
   ---------------------------------------------------------------
   class Vehicle {     
      public void run() {
         System.out.println("차량이 달립니4다.");
      }
   }
   ---------------------------------------------------------------
   2. >>>>  ##### Q2) Driver 클래스를 구현하시오.
   3. 실행메인클래스  Polymorphism15

class Vehicle{ public void run() { System.out.println("차량이 달립니다."); } }

class Bus extends Vehicle{ 
public Bus() { super();  }
@Override
public void run() { System.out.println("버스가 달립니다."); } }

class Taxi extends Vehicle{  
public Taxi() { super();  }
@Override
public void run() { System.out.println("택시가 달립니다."); } }

class Driver{  
public Driver() { super();  }  
void drive(Vehicle v) {v.run();} 
}
   public class Polymorphism15 {
      public static void main(String[] args) {
         Driver driver = new Driver();
         
         Bus bus = new Bus();
         Taxi taxi = new Taxi();
         
         driver.drive(bus);
         driver.drive(taxi);
      }
   }
   
   4.  실행화면
   버스가 달립니다.
   택시가 달립니다.


'구디아카데미' 카테고리의 다른 글

목표설정(2022.6.9)  (0) 2022.06.09
목표달성(2022.6.8)  (0) 2022.06.08
목표달성(2022.6.3)  (0) 2022.06.04
목표달성(2022.06.2)  (0) 2022.06.03
목표달성(2022.5.31)  (0) 2022.05.31

검색 태그