java习题交通工具方法重载

 
  

java习题交通工具方法重载_第1张图片

class Vehicles
{
	String brand;
	String Color;
	public void run()
	{
	System.out.println("我已经开动了");
	}
	public void showInfo()
	{
	System.out.println("商标:"+brand);
	System.out.println("颜色:"+Color);
	}
}

class Car extends Vehicles
{
	int seats;
	public Car(){}
	public Car(String brand,String Color,int seats)
	{
		this.brand=brand;
		this.Color=Color;
		this.seats=seats;
	}
	void showcar()
	{
	super.showInfo();
	System.out.println("座位"+seats);
	}
}

class Truck extends Vehicles
{
	float load;
	public Truck(){}
	public Truck(String brand,String Color,int load)
	{
		this.brand=brand;
		this.Color=Color;
		this.load=load;
	}
	public void showTruck()
	{
		super.showInfo();
		System.out.println("载重"+load);
	}
}

public class Test1
{
	public static void main(String[] args)
	{
		Car benchi=new Car("benchi","white",4);
		benchi.showcar();
		Truck tuolaji=new Truck("tuolaji","black",100);
		tuolaji.showTruck();
	}
}

你可能感兴趣的:(java)