Java Reference
In-Depth Information
Here,
Truck
inherits
Vehicle
, adding
cargocap
,
getCargo( )
, and
putCargo( )
.
Thus,
Truck
includes all of the general vehicle attributes defined by
Vehicle
. It need
add only those items that are unique to its own class.
3.
Next, make the instance variables of
Vehicle
private, as shown here:
4.
Here is an entire program that demonstrates the
Truck
class: