Inheritance in C#

  • Thread starter Thread starter Guest
  • Start date Start date
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,
 
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?
 
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?
 
Back
Top