06 December 2013

Sealed class explained

In this programming tutorial let's understand what is a sealed class by going through the below topic on sealed class:

  1. What is sealed class
  2. How to define a sealed class
  3. Sealed classes .NET framework
  4. Singleton design pattern & sealed class

What is sealed class

Inheritance is one of the building block of the OOPS. However sometimes, allowing a class to be inherited doesn't make sense. In such circumstances, we can make the class cannot be inherited. C# .NET, has exposed a keyword, "sealed", to make a class cannot be inherited. So in essence, the class which cannot be inherited are called Sealed class.

How to define a sealed class

public sealed class BaseClass
As you can see above in the above C# code sample, the keyword "sealed" is used to make the BaseClass as sealed class.

Sealed class .NET framework

Making singleton as sealed class

No comments:

Post a Comment