CoreJava/exp3/VehicleClient.java

24 lines
526 B
Java
Raw Permalink Normal View History

2024-05-09 09:10:51 +08:00
package exp3;
public class VehicleClient
{
public static void main(String args[])
{
System.out.println("输出相关数据");
Car car=new Car("",4,1500,4); //创建一个Car类对象
car.show();
Trunk trunk=new Trunk("", 8,7000,3,25000);
trunk.show();
Vehicle vehicle= new Car("", 4,2000,4);
vehicle.show();
if(vehicle instanceof Car){
((Car)vehicle).show();
}
else{
System.out.println("不能强制转换类型!");
}
vehicle=new Trunk("", 9,8000,4,30000);
vehicle.show();
}
}