Net-informations.com
SiteMap  | About    

What is a sealed class in C#?

Sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as a sealed class, the class cannot be inherited.

The "sealed" modifier is used to define a class as sealed. Sometimes classes are too precious and not designed to be inherited. When applied to a class, the sealed modifier prevents other classes from inheriting from it. The design intent of a sealed class is to indicate that the class is specialized and there is no need to extend it to provide any additional functionality through inheritance to override its behaviour. A sealed class is often used to encapsulate a logic that needs to be used across the program but without any alteration to it.

Sealed classes are primarily used to prevent derivation . Because they can never be used as a base class, some run-time optimizations can make calling sealed class members slightly faster . Sealed class is the last class in the hierarchy. It means you have to think of more possibilities when designing a class as sealed.

What Is Inheritance ?

Inheritance is a fundamental feature of an Object-Oriented programming. It is the process of creating a new Class, called the Derived Class, from the existing class, called the Base Class. Inheritance is a very elegant way to reuse and modify the data and functionality that has already been defined in the Base Class, also you can add new data and functionality to the Derived Class.

More on... Inheritance









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.