Getters Setters Labs
In this lab we will improve the encapsulation of our com.example.inheritance.labs.vehicles.Vehicle hierarchy.
-
Change
Vehicle,Automobile,Truck, andBoatso that all fields areprivate. -
There will be compilation errors. Do not accept any Eclipse suggestions to fix them.
-
Add getters and setters in each class for all fields that do not have them.
-
You can do this in Eclipse by choosing a class and selecting Source->Generate Getters and Setters.

-
Then select fields, and eclipse will generate the methods.

-
Generating getters and setters will only show fields that are visible and do not already have getters and setters defined.
-
Fix compilation errors by using getters and setters instead of directly accessing fields.
-
Run
VehicleTestAppand make sure it still works.
(Solution: Vehicle2.java, Automobile2.java, Truck2.java, Boat2.java, VehicleTestApp2.java)