java一段简单程序的问题,写个构造方法

来源:百度知道 编辑:UC知道 时间:2024/05/27 03:44:50
/**
* AircraftCarrier class. An "Aircraft Carrier" is the biggest
* ship in the Battleships game, occupying five grid squares.
*/
public class AircraftCarrier extends Ship {
/**
* AircraftCarrier constructor. Initialises the name and length of the AircraftCarrier.
*/
public AircraftCarrier() {

}
}
Initialises the name and length of the AircraftCarrier.

public class AircraftCarrier extends Ship {
/**
* AircraftCarrier constructor. Initialises the name and length of the AircraftCarrier.
*/
String name;
int strLength;

public AircraftCarrier(String name,int strLength) {
this.name=name;
this.strLength=strLength;
super();
}
}

public class AircraftCarrier extends Ship {
/**
* AircraftCarrier constructor. Initialises the name and length of the AircraftCarrier.
*/
public AircraftCarrier() {
super();
//或者可以用 super(String name,int length);

}
}

public AircraftCarrier(String name,int length) {
this.name = name;
this.length = length;
/* or
* super.setName(name);
* super.setLength(length);
*
}

public AircraftCarrier() {

}
这不就是构造方法吗