GeekInterview.com
Series: Subject: Topic:
Question: 65 of 85

Can we inherit private members of class ?

Asked by: Interview Candidate | Asked on: Jul 27th, 2006
Showing Answers 1 - 13 of 13 Answers
yash

Answered On : Jul 28th, 2006

we cannot inherit private members of a class

Yes  1 User has rated as useful.
  
Login to rate this answer.
AvinashChaturvedi

Answered On : Aug 3rd, 2006

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 )

  
Login to rate this answer.
RAJEEV CHOPRA

Answered On : Sep 8th, 2006

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.

  
Login to rate this answer.
dhivya

Answered On : Oct 27th, 2006

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.

Yes  2 Users have rated as useful.
  
Login to rate this answer.
neverd

Answered On : Jun 12th, 2007

View all answers by neverd

ye, make the derived class a friend class of the base class

  
Login to rate this answer.
wael.salman

Answered On : Jul 16th, 2008

View all answers by wael.salman

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.

  
Login to rate this answer.
wael.salman

Answered On : Jul 16th, 2008

View all answers by wael.salman

For more explanation, you can see in my  previous answer that we can inherit, but we can not access it from the derived class.

  
Login to rate this answer.
kayalammu

Answered On : Sep 22nd, 2010

View all answers by kayalammu

No we cannot inherit the private member of a superclass.

  
Login to rate this answer.
sandeep

Answered On : Jul 18th, 2011

we can inherit with get set properties.

  
Login to rate this answer.
sundar

Answered On : Jul 22nd, 2011

we can inherit in the private mode of visibility.

  
Login to rate this answer.
vikas

Answered On : Jul 26th, 2011

yes by making it friend class

  
Login to rate this answer.
sean

Answered On : Oct 10th, 2011

if you can declare the sub class in the base class (i.e if you make sub class as inner class in base class), you will be able to access the private members of the base class.

  
Login to rate this answer.
ProgrmmingBOT

Answered On : Nov 20th, 2011

View all answers by ProgrmmingBOT

we cannot inherit private members of a class,but you can use friend functions to access private data

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.