Hi~ I am new here
I was just following a tutorial from a book
and I found something that I can't understand
Here's my source code:
public class Airplane2 {
private String nameOfAirp = "C10111";
private int fuel = 10000;
private int goPerL = 10; //Km/Liter
public Airplane2(String nameOfAirp, int fuel, int goPerL){
this.nameOfAirp = nameOfAirp;
setFuel(fuel);
this.goPerL = goPerL;
}
public Airplane2(String nameOfAirp, int fuel){
this(nameOfAirp, fuel, 10);
}
public Airplane2(String nameOfAirp){
this(nameOfAirp, 10000, 10);
}
public Airplane2(){
this("C10111", 10000, 10);
}
public void setFuel(int fuel){
if(fuel < 1000){
System.out.println("Lack of fuel!!");
this.fuel = 0;
return;
}
this.fuel = fuel;
}
public int getFuel(){return fuel;}
public int getGoPerL(){return goPerL;}
public String getNameOfAirp(){return nameOfAirp;}
public String toString(){
String s = "";
if(fuel > 999){
s = "Name of the plane: " + nameOfAirp;
s += " Flight distance: " + goPerL*fuel;
}
else{
s = "This plane cannot depart!!";
}
return s;
}
}
public class Airplane2Main {
public static void main(String[] args){
Airplane2 air948 = new Airplane2("Eagle Five", 6000, 11);
System.out.println(air948.toString());
Airplane2 air947 = new Airplane2("Center Five");
System.out.println(air947);
Airplane2 air949 = new Airplane2();
System.out.println(air949);
}
}
I am curious about the texts.
I thought there should be air947.toString and air949.toString like air948.toString
but there was no compile error.
Why is that???