What is sealed Class in C#?
What is sealed Class in C#?
A sealed class in C# is a class that cannot be inherited from or derived by other classes. It is marked with the sealed
keyword and prevents further inheritance[1][2][3][4].
The main purposes of sealed classes are:
To restrict inheritance and prevent other classes from deriving from it[1][2][3][4]. This can help prevent security issues by not allowing methods in the sealed class to be overridden and manipulated by other classes[3].
Sealed classes are often used for classes with static members, such as the Pens
and Brushes
classes in the System.Drawing
namespace. These classes represent standard colors and have only static members[1][3].
When overriding virtual methods, you can seal them by using the sealed
keyword. This allows derived classes to inherit from the class but prevents them from overriding those speci...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào