GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Concepts  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 21 of 68    Print  
Can we inherit private members of class ?

  
Total Answers and Comments: 7 Last Update: July 16, 2008     Asked by: Anjaly 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: dhivya
 

Private members cannot be inherited,

only public and protected members can be inherited.

private members can be accessed with the help of FRIEND function.

protected members can inherit as protected,public members can be inherited as public, but private cannot be inherited.



Above answer was rated as good by the following members:
VCCoder
July 28, 2006 05:28:33   #1  
yash        

RE: Can we inherit private members of class ?
we cannot inherit private members of a class
 
Is this answer useful? Yes | No
August 03, 2006 07:12:08   #2  
AvinashChaturvedi Member Since: August 2006   Contribution: 4    

RE: Can we inherit private members of class ?

Hi

There is only one case in which u can inherit a member into derived class by using PROTECTED Access specifire for that member . a member with protected specifire remain private for same class but it is possible to inherit this member into derived classes so this is the only way for this problem.

Regards

Avinash Chaturvedi ( Avi )


 
Is this answer useful? Yes | No
September 08, 2006 17:03:46   #3  
RAJEEV CHOPRA        

RE: Can we inherit private members of class ?
If we specify access specifier private to member of any class means it is private for that class.


Means child can inherit when parent will permit.


So if it is private it cannot be inherited.

 
Is this answer useful? Yes | No
October 27, 2006 00:54:11   #4  
dhivya        

RE: Can we inherit private members of class ?

Private members cannot be inherited

only public and protected members can be inherited.

private members can be accessed with the help of FRIEND function.

protected members can inherit as protected public members can be inherited as public but private cannot be inherited.


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 12, 2007 18:49:20   #5  
neverd Member Since: June 2007   Contribution: 11    

RE: Can we inherit private members of class ?
ye make the derived class a friend class of the base class
 
Is this answer useful? Yes | No
July 16, 2008 06:52:41   #6  
wael.salman Member Since: July 2008   Contribution: 6    

RE: Can we inherit private members of class ?

We cannot even we use protected inheritance

Look:

class Dericed: protected Base

{

}



Protected inheritance

It is almost never used except in very particular cases. With protected inheritance the public and protected members become protected and private members stay private.

To summarize in table form:

Protected inheritance
Base access specifier Derived access specifier Derived class access? Outside access?(Other calsses)
Public Protected Yes No
Private Private No No
Protected Protected Yes No

Protected inheritance is similar to private inheritance. However classes derived from the derived class still have access to the public and protected members directly. The public (stuff outside the class) does not.


 
Is this answer useful? Yes | No
July 16, 2008 06:54:53   #7  
wael.salman Member Since: July 2008   Contribution: 6    

RE: Can we inherit private members of class ?
For more explanation you can see in my previous answer that we can inherit but we can not access it from the derived class.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape