class Car
{
public String make;
protected int weight;
private String color;
public Car(String make,int weight,String color)
{
this.make=make;
this.weight=weight;
this.color=color;
}
public Car()
{
this("unknown",-1,"white");
}
class ElectricCar extends Car
{
private int rechargeHour;
public ElectricCar()
{
this(10);
}
public ElectricCar(int charge)
{
super();
rechargeHour=charge;
}
}
class TestMain
{
public void main(String[]args)
{
Car myCar1,myCar2;
ElectricCar myElce1,myElce2;
myCar1=new Car();
myCar2=new Car("Ford",1200,"Green");
myElce1=new ElectricCar();
myElce2=new ElectricCar(15);
}
}
}
dengt 于 2011-01-09 11:08:28发表:
不太懂Java