Encapsulation is one of the 4 main OOP principles.
It protects the class data from access outside the class body.
Result:
Explanation:
_model
and _manifactureYear
) can only be accessed / modified by
functions defined inside the class (in this case getters and setters). Access outside the class body is done via
helping members (model
and manifactureYear
).
line 50
the code won't compile. A direct access
to private members cannot be done outside the class body.Output:
All members are accessible outside the class body.