GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 174 of 185    Print  
Private Inheritance question
Hi I very recently did the C++ online Quiz and was surprised to find that my answer (1) to the following question (below) was incorrect. Is there something I am missing here, or is the answer incorrect. I thought this was the point of Private. "Always inaccessible regardless or derivation access".
Apparently (3) in the correct answer! according to the quiz!

The private member in derived class
1) Cannot be inherited
2) Can be inherited at all instances
3) Can be inherited only if the derived class is inheriting from base class with private access level
4) None of the Above



  
Total Answers and Comments: 4 Last Update: September 29, 2008     Asked by: BronzeBill 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: charliearcuri
 
I think you are correct, BronzeBill.  I just tried an experiment using MFC: ChildClass inheriting privately from ParentClass which has a private member - that private member is *not* accessible in a ChildClass method even though ChildClass : private BaseClass.

Above answer was rated as good by the following members:
zeal_goswami
September 02, 2008 19:46:06   #1  
charliearcuri Member Since: September 2008   Contribution: 1    

RE: Private Inheritance question
I think you are correct, BronzeBill.  I just tried an experiment using MFC: ChildClass inheriting privately from ParentClass which has a private member - that private member is *not* accessible in a ChildClass method even though ChildClass : private BaseClass.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
September 23, 2008 06:22:18   #2  
beharav Member Since: September 2008   Contribution: 2    

RE: Private Inheritance question
Your answer is right. Its 1. There is no way you can access a private member of a base class in the derived class by inheriting privately.
 
Is this answer useful? Yes | No
September 26, 2008 07:34:11   #3  
gpuchtel Member Since: September 2008   Contribution: 1    

RE: Private Inheritance question
You are confusing inheritance with accessability. Private members are indeed inherited. That is, there is a slot for it in the ‘vbtl’ when the class is constructed; however, you don’t have access to it from a derived class, unless the base class has made you a ‘friend’. If ‘private’ members were not inherited, how would ‘friend(ship)’ work? So, inheritance means ‘what do I (physically) get’, not ‘what can I (logically) see’.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
September 29, 2008 02:21:39   #4  
hrisheekesh.kale27 Member Since: September 2008   Contribution: 4    

RE: Private Inheritance question
gpuchtel's answer makes sense to me. The fact that size of the derived class object is sum of size of all the public and private members of base class and derived class corroborates the argument.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape