Rules of inheritance, C/C++ Programming

Rules of Inheritance:

  • Private members are not inherited; the members can be accessed only within its class. It cannot be used through the object.
  • Protected members are inherited; but it can be used only within the base and inherited derived class. It cannot be accessed through the object.
  • Public members are inherited, and public members only can be accessed inside the class as well as outside the class through objects.
  • The private member and protected member can be accessed outside the class indirectly, that is passing these members in the public members.
  • Class inherited as private will make all the members of the base class as private in the derived class; and it has to follow the rules of private member to access.
  • Class inherited as protected will make all the members of the base class as protected in the derived class; and it has to follow the rules of protected member to access.
  • Class inherited as public will not make any changes to the members of base class in the derived class.
  • The derived class cannot modify the original characteristic of its base class.
  • The multiple copies of same class may happen during multiple inheritances. This can be avoided by created virtual base class using "public virtual" key word this make only one copy to be inherited from base classes.
  • Constructor is not inherited but arguments can be passed from the derived class to the base class constructor using colon operator.
  • Objects be able to nested, and it is not inheritance.
  • When the base class and the derived class has the same member function name, only the derived class member can be accessed through derived class object. In this case the base class member function is overridden. The base class member function can be accessed through derived class object only through scope operator if the derived as public.

 

 

Posted Date: 9/20/2012 8:21:05 AM | Location : United States







Related Discussions:- Rules of inheritance, Assignment Help, Ask Question on Rules of inheritance, Get Answer, Expert's Help, Rules of inheritance Discussions

Write discussion on Rules of inheritance
Your posts are moderated
Related Questions
program to write superposition of waves using class and objects

We have used logic symbols in the past, but not really though about the actual real devices. Semiconductor companies have taken the logic symbols are manufactured them into logic f

#question write a prog c & cpp

Unlike C++, other programming languages have associative arrays that allow array indices to be strings instead of just integers. You are to create a template class, SVector, that i

It is a pointer accessible only in the member functions of a struct, class or union type. It points to the object for which the member function is called. Static member functions d

Explain about the Constants in c language? The Constants in C refer to fixed values that don't change during the execution of a program. C has four fundamental types of constan

Consider the following mathematical function: (a) Write a procedure that computes f by means of a recursive process (b) Write a procedure that computes f by means of an

write a c program to compute a padovan string

Suppose that three integer variables intA, intB, and intC have already been defined at the beginning of the main function, write a single C++ statement to read three integers from