Câu hỏi phỏng vấn C#
Câu hỏi

What is sealed Class in C#?

Câu trả lời

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:

  1. 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].

  2. 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].

  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

middle

Gợi ý câu hỏi phỏng vấn

middle

What is Extension Method in C# and how to use them?

middle

What is the use of the IDisposable interface?

middle

How can you prevent a class from overriding in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào