I think the book forgot to explain this: two of the same method?
Code:
public static final String DEFAULT_COLOR = "white";
public String name;
public boolean running;
public String color;
public int numMiles;
[COLOR="Red"] public Automobile() {[/COLOR]
this(false, DEFAULT_COLOR, 0);
}
[COLOR="Red"]public Automobile(boolean running, String color, int numMiles) {[/COLOR]
this.running = running;
this.color = color;
this.numMiles = numMiles;
name = null;
}
I am currently studying methods and objects. This was part of the code from the book "Java Programming For The Absolute Beginner". I just missed out on understanding this code though.
1) Can you explain this(false, DEFAULT_COLOR, 0);. Does "this" just take over any method that is the same as the class name?
2) Why are there 2 public Automobile methods made in this class Automobile? It seems that the code above "this(false, DEFAULT_COLOR, 0);" would interfere with its current method.
3) Wouldn't it have been better to just do this instead of adding two Automobile methods? Wouldn't that do the same thing?
Code:
public String name = null;
public boolean running = false;
public String color = "white;
public int numMiles = 0;