Chapter 3 – Object-Oriented Programming: Part 3
Access modifiers are public, protected, and private.
Public means we can access the variable / call the method from everywhere.
Protected means that the class itself and the derived classes can access the variable / call the methods.
Private means only the class itself can access the variable / call the methods.
This is the highest level a variable / method can have in derived classes, when we inherit from classes.
When we inherit publicly, we inherit the public data and the protected data. Since public inheritance is the most relaxed (accessible from everywhere), nothing changes – same access it had in the base class, it will have in the derived class.
When we inherit as protected, this is the highest access for what we inherit from. Thus, anything that was public in Base class will be protected here.
If we inherit privately, anything that was public or protected in Base class will come as private in the derived class.
Function overload and override
Function overload mean we can have the same function name, but with different parameter number/type, and /or different return type. Overload cannot be done on the return type itself only.
Override means we can have a function in the base class, and override it (implement it differently) in the derived class, thus hiding the function from Base.