Can we inherit private members of class ?

Showing Answers 1 - 25 of 25 Answers

yash

  • Jul 28th, 2006
 

we cannot inherit private members of a class

AvinashChaturvedi

  • 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 )

  Was this answer useful?  Yes

RAJEEV CHOPRA

  • 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.

  Was this answer useful?  Yes

dhivya

  • 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.

wael.salman

  • Jul 16th, 2008
 

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.

  Was this answer useful?  Yes

sandeep

  • Jul 18th, 2011
 

we can inherit with get set properties.

  Was this answer useful?  Yes

sundar

  • Jul 22nd, 2011
 

we can inherit in the private mode of visibility.

  Was this answer useful?  Yes

vikas

  • Jul 26th, 2011
 

yes by making it friend class

  Was this answer useful?  Yes

sean

  • 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.

  Was this answer useful?  Yes

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions