Question:
it possible to inherit the private member in drived class?
Answer:
yes, if the derived class is inheriting from base class with private access level<br><br>class derived : private base<br> Source: CoolInterview.com
but it's not mean that we can inherit privete member of base class....... if we are inheriting base class in privete mode that means base class function will use like privete member of derive class and in any condition we can not inherit private function of base class........ Source: CoolInterview.com
Answered by: mayank kumar sharma | Date:
| Contact mayank kumar sharma
Hi Friends, Actualy there r three access mode in C++,(i)public (ii)protected (iii)private.public can be accessed from anywhere<br>& protected can be access only by derived class;But if we made a variable private it can be accessed by scope resiolution operator(::)from outside the class.if this derived class is inheriting the private member from base class then it is possible to inherit the private member in derived class. <br> <br> Source: CoolInterview.com
Answered by: Ravi Mehta | Date:
| Contact Ravi Mehta
Yes,we can inherit the private member into derived class. 1st we inherit base class into derived class in public mode,now public member of base class too public member of derived class,than we can call the private member by public function of derived class. Source: CoolInterview.com
Answered by: Ravi jha | Date: 6/16/2009
| Contact Ravi jha
yes the private member of base class is automaticaly inherited in drived class but can not be use and visible in drive class Source: CoolInterview.com
Answered by: gaurav | Date: 8/1/2009
| Contact gaurav
#include "stdafx.h"<br>#include "iostream"<br>using namespace std;<br><br>class base<br>{<br>private : <br> int s;<br>public:<br> int pub;<br> base(){<br> s=20;<br> pub=10;<br> }<br> virtual void getV(){<br> printf("%d",s);<br> }<br>};<br><br>class der : public base<br>{<br>};<br><br><br>int _tmain(int argc, _TCHAR* argv[])<br>{<br><br> der d;<br> d.getV();<br> cout<<d.pub;<br> return 0;<br>}<br><br> Source: CoolInterview.com
Answered by: Swapnil Patil | Date: 11/2/2009
| Contact Swapnil Patil
Yes, private member of the base class can be inherit in the derived class but can't be visible and access.<br>e.g. the size of derived class is equal to the sum of the base class and derived class data members. It means that the base class data members comes into the derived class but visibility is depend on the mode and inherit type. Source: CoolInterview.com
Answered by: Sweta | Date: 5/25/2010
| Contact Sweta
no a private member can never be accessed outside class only teh calss memebers can access it . Source: CoolInterview.com
Answered by: pavithra | Date: 7/7/2010
| Contact pavithra
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|