Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
2.00/5 (5 votes)
See more:
a derived class inherits the private members of a base class also.
Is it true or false??

I know it is very simple one.But Please give me the answer..


(I am not asking your concept is clear or not... Just give the answer ...)
If you know then, first confirm it and check the answers in down,if you are confident !!
Posted
Updated 13-Apr-12 4:11am
v6
Comments
[no name] 13-Apr-12 10:00am    
Here's an idea.... why don't you try it and find out?
samu4u 13-Apr-12 10:03am    
This thing i tried already... thats why i given the question??(I made the mistake first...)
Everybody asking tough questions, So i made it is simple...
[no name] 13-Apr-12 10:10am    
If you already know the answer then why are you asking the question? This is not a debate forum.
samu4u 13-Apr-12 10:12am    
I am sorry master...please forgive me..

false, only protected or public members are visible. You can find more information on MSDN.
 
Share this answer
 
Comments
samu4u 13-Apr-12 9:41am    
I am not asking is it visible or not..simply inherit or not??
Sure.?Check in MSDN itself again and confirm it...
V. 13-Apr-12 9:44am    
If it's not even visible, do you think it is inherited?
samu4u 13-Apr-12 9:48am    
Yes.
V. 13-Apr-12 9:49am    
Please read my answer... it starts with "false, ..."
samu4u 13-Apr-12 9:50am    
I am saying a derived class inherits the private members of a base class also.
True.

Contrary to V.'s solution, just because it is not readily accessible does not mean it is not inherited. An instance of the derived class will still instantiate the private members of the base class, they just will only be accessible through the base class's methods.
 
Share this answer
 
Comments
samu4u 13-Apr-12 10:00am    
good...Dont feel that this is a simple question, may be people will make mistakes...
A derived class has access to the public, protected, internal, and protected internal members of a base class. Even though a derived class inherits the private members of a base class, it cannot access those members. However, all those private members are still present in the derived class and can do the same work they would do in the base class itself. For example, suppose that a protected base class method accesses a private field. That field has to be present in the derived class for the inherited base class method to work correctly.

http://msdn.microsoft.com/en-us/library/ms173149.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900