红联Linux门户
Linux帮助

调用构造方法!

发布时间:2005-05-17 22:06:25来源:红联作者:wade9900
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);
}
}
}
文章评论

共有 1 条评论

  1. dengt 于 2011-01-09 11:08:28发表:

    不太懂Java