About Me

Wednesday, December 29, 2010

Why abstract method can't be private

Not so far ago I had to use abstract class for one business implementation.
I quickly typed the construction of abstract class and then found that the intelisense mark some code as invalid:
My first question was "Why?!".
Why abstract method can't be private ?

Here is the answer that came into my brain in the next second:

Abstract clause means that the method should be overriden in the classes that are inheriting from the base class.
In this case, each inheritor from Foo class should implement Method1, Method2 and Method3
Inheritor, can see only public and protected members of the base class. 
So, there is no way to implement Method3 because it marked as private.

No need to remember all the rules about all that OOP tricks in .NET, its only need to use your brain and ask "Why?" at the right moment. There is always logical explanation for it.

No comments:

Post a Comment