Because there are some excellent answers to the question "why is this possible?". I think C # deserves an explanation of why this is NOT possible: it is about the โphilosophyโ of language design and can be reduced to โis-aโ versus โhasโ a clash of ideas.
C ++ is all about thinking "has-a", some of which were passed to D and Java. B has a foo
method, and this is most important for both the compiler and the programmer, not B. In C ++, you can even override a method as private (or inherit a class as private), which means that member A will NOT be displayed B.
C # - hardcore about the is-a concept. Therefore, since B really is A here, everything in B should be exactly the same as in A. Neither the compiler nor the programmer should worry about the changes, because no changes are possible. B is always the perfect replacement for A.
The is-a philosophy forbids the C # program to publish a previously protected member, although it is trivial to do this through a public shell. It makes little sense, and here it is just a slight inconvenience, but it is very important to adhere to the philosophy of language.
source share