Why can an abstract class not be sealed or static?
And I am also confused about the question Why declare static classes as sealed and abstract in C#?.
Why can an abstract class not be sealed or static?
And I am also confused about the question Why declare static classes as sealed and abstract in C#?.
Copyright © 2021 Jogjafile Inc.
static
class cannot be markedsealed
because it is madesealed
by compiler by default.static
class cannot be marked asabstract
, because it would be pointless.abstract
class makes sense when you want all derived classes to implement same part of the logic. But becausestatic
class cannot be derived there is no way other class will implement these gaps.Both quotes from Static Classes and Static Class Members (C# Programming Guide).
C# specification is a little more detailed about that:
You can read what does it mean for class to be
sealed
orabstract
:Update
And a word about an article linked in the query you mentioned (Static Class Design). It's already stated in accepted answer from that question. If you read carefully you can see that:
.NET (so C# as well) do have built-in support for static classes, so you don't have (and even can't) to make your classes pseudo-static by marking it both
sealed
andabstract
.