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
How would you print the values of the variables words and lines so they appear in the form: There were 6040 words and 680 lines. Here, 6040 and 680 represent the values of the two

Constructor and Destructor function with derived classes If there are constructors included in the base class and the derived class, the compiler automatically calls both of th


Project Description: I want a script for an online poker site. It needs to be scanning all the required tables and when the table meets certain criteria it should take a seat at

Although we can handle most I/O routines with getc and putc , there are file versions of fgets, fputs, fprintf and fscanf . The syntax is       fgets(stringname,n,filename);   Th

Write a program that reads a line of characters from the user and displays that entire line after converting any uppercase characters to lowercase also change any lowercase charact

Provide me the answer, Can a constructor throws an exception? How to handle the error when the constructor fails?

Returning References from Functions Just as in passing the parameters by reference, returning a reference also doesn't return back a copy of the variable , instead an alias is

Aim: To implement a program for bank account using static data type. Code: class bank {             static int acc_no;             int acc;             float b

Define the System Oriented Data Files? System-oriented data files are further closely related to the computer's operating system than Stream- oriented data files and they are s