package car;
//예상결과를 작성하고 Run-time Error!를 수정하세요.
public class ObjectCastingTest{
public static void main(String args []){
Car car = new Car();
System.out.println("car.Carname="+car.carname+"\n");
Jeep j = new Jeep();
System.out.println("j.carname="+j.carname);
Car carTypej = new Jeep();
System.out.println("carTypej.carname="+carTypej.carname);
System.out.println("carTypej intanceof Jeep = "+(carTypej instanceof Jeep));
Jeep JeepFromCarTypeJeep = (Jeep)carTypej;
System.out.println("JeepFromCarTypeJeep.carname="+JeepFromCarTypeJeep.carname+"\n");
System.out.println("JeepFromCarTypeJeep intanceof Jeep="+(JeepFromCarTypeJeep instanceof Jeep));
// Jeep car2j = (Jeep)car;
// System.out.println("car2j instanceof Jeep = "+(car2j instanceof Jeep));
BMW b = new BMW();
System.out.println("b.carName="+b.carname);
Car carTypeBMW = new BMW();
System.out.println("carTypeBMW.carName="+carTypeBMW.carname);
System.out.println("carTypeBMW instanceof BMW = "+(carTypeBMW instanceof BMW));
BMW BMWFromCarTypeBMW = (BMW)carTypeBMW;
System.out.println("BMWFromCarTypeBMW.carname="+BMWFromCarTypeBMW.carname+"\n");
System.out.println("BMWFromCarTypeBMW instanceof BMW = "+(BMWFromCarTypeBMW instanceof BMW));
// BMW car2b = (BMW)car;
// System.out.println("car2b instanceof BMW = "+(car2b instanceof BMW));
Volkswagen v = new Volkswagen();
System.out.println("ca.carname="+v.carname);
Car carTypeVolkswagen = new Volkswagen();
System.out.println("carTypeCanival.carname="+carTypeVolkswagen.carname);
System.out.println("carTypeCanival instanceof Canival = "+(carTypeVolkswagen instanceof Volkswagen));
Volkswagen VolkswagenFromCarTypeVolkswagen=(Volkswagen)carTypeVolkswagen;
System.out.println("canivalFromCarTypeCanival.carname="+VolkswagenFromCarTypeVolkswagen.carname);
System.out.println("canivalFromCarTypeCanival instanceof Volkswagen="+(VolkswagenFromCarTypeVolkswagen instanceof Volkswagen));
// Volkswagen car2ca = (Volkswagen)car;
// System.out.println("car2ca instanceof Canival = "+(car2ca instanceof Volkswagen));
}
}
댓글 없음:
댓글 쓰기