September 2011
Beginner
650 pages
15h 47m
English
We can improve the Vehicle class by adding a constructor that automatically initializes the passengers, fuelcap, and mpg fields when an object is constructed. Pay special attention to how Vehicle objects are created.


Both minivan and sportscar are initialized by the Vehicle( ) constructor when they are created. Each object is initialized as specified in the parameters to its constructor. For example, in the following line,
the values 7, 16, and 21 are passed to the Vehicle( ) constructor when new creates ...
Read now
Unlock full access