Default Constructors and Object Parameters

A class with no constructor
public class Scooter
{
private String rider;
private int trips;
private int speed;
}
Scooter declares no constructor, and new Scooter() still compiles. The constructor Java supplies sets no values of its own, so every instance variable keeps its default value.
For a new Scooter, the two counts start at 0 and rider is null. The value null means the variable refers to no String at all, which is different from the empty string "". Calling rider.length() would throw a NullPointerException when that line runs, while "".length() is 0.
Java provides the default constructor only while the class declares none. Adding public Scooter(String name) to the class removes it, and new Scooter() then fails to compile, since no constructor with an empty parameter list exists.
A constructor that skips an instance variable is legal. If Scooter(String name) sets only rider, the two counts still hold 0. A local variable is different: one that is declared but never assigned can't be read at all.
Storing an object that was passed in
A scooter rental keeps a Helmet for each customer, and a helmet's fit can be adjusted.
public class Helmet
{
private int fit;
private String color;
public Helmet(int cm, String c)
{
fit = cm;
color = c;
}
public int getFit()
{
return fit;
}
public String getColor()
{
return color;
}
public void adjust(int change)
{
fit = fit + change;
}
}
A Helmet is mutable: it has a method that changes its state. Suppose a Rental class keeps one in an instance variable private Helmet gear;, and its constructor stores the helmet it is given with gear = h;. The parameter holds a reference, so that assignment copies the reference. The caller and the rental now reach one Helmet object, and the caller can adjust the helmet the rental is holding long after the constructor has finished.
public Rental(Helmet h)
{
gear = new Helmet(h.getFit(), h.getColor());
}
getFit() returns an int, a plain value, and getColor() returns a String, which the two helmets can share safely because no String method changes the string it's called on. new Helmet(...) builds a second helmet from them, and the caller's helmet and the rental's helmet are now separate objects.