What is the output of the code

public class B : A { }

Options
- Errors
- It defines a class that inherits the public methods of A only.
- It defines a class that inherits all the methods of A but the private members cannot be accessed.
- b and c


CORRECT ANSWER : It defines a class that inherits all the methods of A but the private members cannot be accessed.

Discussion Board
Correct and logical to boot

Option d is clearly wrong as b & c cannot be both true.
Option c is correct as an instance of a derived class must contain the private members of a base class in order to work, as stated in the SO reference given below.
The private vs internal modifiers in an inheritance tree give a nice way to choose visibility as required, i.e implements encapsulation in the inheritance scenario.


Ackroydd 04-19-2015 09:55 AM

Agree and disagree

Agree that it's a bad choice of answers, but disagree that b and c appears to be right. It can never be considered correct that a class would inherit public members only (never mind public METHODS only)... so by elimination the correct answer is found, which brings me to the bad choice part.

In truth, I find the terminology used on this site to be misleading in many places (methods instead of members, specified base class instead of declaring type, etc.) and technically incorrect quite often.

Posting this here since after 20-or-so questions this is the last one I'll visit. Please, if you're going to even remotely attempt to help people's understanding of a topic, then for goodness' sake be correct about it.


Peter-John Lightfoot 09-26-2014 06:01 AM

Bad choice of answers

http://stackoverflow.com/questions/2950820/are-private-members-inherited-in-c

Option C reads like it's the correct answer, so b and c appears to be right.

Shaun 08-13-2014 06:06 AM

Write your comments

 
   
 
 

Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement