Car.java.html

  1  public class Car extends Vehicle
  2  {
  3     // This instance variable is added to the subclass
  4     private String licensePlateNumber;
  5     
  6     public Car()
  7     {
  8        setNumberOfTires(4); 
  9        licensePlateNumber = "??????";
 10     }
 11  
 12     public void setLicensePlateNumber(String newValue)
 13     {
 14        licensePlateNumber = newValue;
 15     }
 16  
 17     public String toString() 
 18     {
 19        return super.toString() + "[licensePlateNumber=" + licensePlateNumber + "]";
 20        // This is a good way of implementing toString in a subclass--see Special Topic 9.6
 21     }
 22  }