INHERITANCE
Base class is publicly inherited: Public members of the base class become public members of the derived class.
Base class is privately inherited: Public members of the base class become private members of the derived class.
Private members can never be inherited. But they can be accessed through inherited member functions of the base class.
protected visibility modifier: a member declared as protected is accessible by member functions within its class and any class immediately derived from it.
A protected member can never become public in the derived class, it can either be protected or private (not available for further inheritance)
If inheritance is done in protected mode then both the public and the protected members become protected in the derived class.
Multiple Inheritance : the base classes are separated by commas. If both the base classes have the same function name, then ambiguity can be removed by defining a named instance M::display ();
When derived class overrides the base class function then we can use
b.A::display () ; where b is derived class object and A is the base class.
Virtual Base Classes
Multiple inherited paths can be avoided if the common base class is made a virtual base class.
class b1 : public virtual A
Abstract Classes used only for inheritance (base class), no objects are created
Constructors in Derived classes
If any of the base class has a constructor then it is mandatory for the derived class to have constructors to pass on the values for the constructors of the base class.
How are the base classes constructed? In the order in which they appear in the declaration of the derived class (Multiple) and for multilevel it is executed in the order of inheritance.
Virtual base gets precedence over an ordinary base
Nesting of Classes: Constructors of all the member objects should be called before its own constructor body is executed.
No comments:
Post a Comment