Welcome to GeekInterview.com
Your professional forum for technical and career related questions
- » You have a interview question or a tech faq and seek help?
- » You want to get an explanation of technical issues?
- » You have questions about your career?
- » You are fresher and concerned about your career?
...then you have come to the right place!
we will try to help you with your problem.
As we know derived class inherit all the features of Base class and it also add its own features ,data etc .............
When a class is inherited all the functions and data member are inherited, although not all of them will be accessible by the member functions of the derived class. But there are some exceptions to ........................
Some of the exceptions to be noted in C++ inheritance are as follows.
- The constructor and destructor of a base class are not inherited
- the assignment operator is not inherited
- the friend functions and friend classes of the base class are also not inherited.
There are some points to be remembered about C++ inheritance. The
protected and
public variables or members of the base class are all accessible in the derived class. But a private member variable not accessible by a derived class.
It is a well known fact that the private and protected members are not accessible outside the class. But a derived class is given access to protected members of the base class
In C++ there are three inheritance access specifiers:
Any of these three inheritance access specifiers can be modified with the
virtual keyword. In my experience interviewing candidates for c++ positions, I've learned that the average programmer does not know how these are used, or even what they mean. So I thought I would go over them here.
The three access modifiers
public,
protected and
private are analogous to the access modifiers used for class members.
- public
- When a base class is specified as
public ie: class c : public base {}; the base class can be seen by anyone who has access to the derived class. That is, any members inherited from base can be seen by code accessing c.
- protected
- When a base class is specified as
protected ie: class c : protected base {}; the base class can only be seen by subclasses of C.
- private
- When a base class is specified as
private ie: class c : private base {}; the base class can only be seen by the class C itself.