| Class Inheritance | ||||||||||||
| Intro to Class Inheritance | Examples of Class Inheritance | |||||||||||
| Public vs. Private or Protected | Abstract Classes | |||||||||||
| Home | ||||||||||||
| Public vs. Private or Protected
Public variables and methods are inherited from the parent class. Children classes do not inherit private attributes and methods. Protected data can be accessed by any class in the same package. Protected type of access provides an intermediate between public and private access type. A child class can be derived privately from its parent class. For example in the public class Car, Engine is privately derived from the base class Car. class Car: private Engine { // Car has-a Engine public: Car() : Engine(8) { } // Initializes this Car with 8 cylinders using Engine::start; // Start this Car by starting its Engine }; |
||||||||||||