Inheritance in C#

G

Guest

Im reading C# specification, an it says that members of class B include all members declared in class B plus all members from its base class (call it class A) REGARDLESS of their accessibility level, meaning 'private int count' (declared in A) would be inherited in B (but would not be accessible, because it is private)

What is the purpose of this inheritance without accessibility? Why cant we just say it is not inherited? What can we do, in class B, with those members inherited from class A that are inaccessible in class B? In other words, what difference would it make if it were not inherited as opposed to having it inherited

Just curious ..

Regards All,
 
J

Jon Skeet [C# MVP]

Dean said:
Im reading C# specification, an it says that members of class B
include all members declared in class B plus all members from its
base class (call it class A) REGARDLESS of their accessibility level,
meaning 'private int count' (declared in A) would be inherited in B
(but would not be accessible, because it is private).
Yes.

What is the purpose of this inheritance without accessibility? Why
cant we just say it is not inherited? What can we do, in class B,
with those members inherited from class A that are inaccessible in
class B? In other words, what difference would it make if it were not
inherited as opposed to having it inherited?

If it weren't inherited, then an instance of B wouldn't have all the
members of an instance of A - so what would code in A but inherited in
B do when it wanted to access those members?
 
B

Bruno Jouhier [MVP]

Hi Dean,

This is an implementation issue, not a semantic issue. The instances of the
subclass must be big enough to contain all the fields (even private ones) of
the base class + all the fields declared in the subclass. That's all.

Bruno.

Dean said:
Im reading C# specification, an it says that members of class B include
all members declared in class B plus all members from its base class (call
it class A) REGARDLESS of their accessibility level, meaning 'private int
count' (declared in A) would be inherited in B (but would not be accessible,
because it is private).
What is the purpose of this inheritance without accessibility? Why cant
we just say it is not inherited? What can we do, in class B, with those
members inherited from class A that are inaccessible in class B? In other
words, what difference would it make if it were not inherited as opposed to
having it inherited?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top