How do you prevent a class from being inherited in c#?



How do you prevent a class from being inherited in c#?..

Answer / Vivek Gupta

In C#, you can prevent a class from being inherited by making it an abstract class or by using the sealed keyword. To make a class an abstract, use the 'abstract' keyword before its declaration, which means that the class cannot be instantiated and must be inherited by another class. To seal a class, use the 'sealed' keyword before the class declaration, indicating that it cannot be further subclassed.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What do you understand by 'access specifiers' in C#?

1 Answers   Genpact,


Can you mark static constructor with access modifiers?

1 Answers  


What is a concrete class in c#?

1 Answers  


How many catch blocks can be there for a single try block?

5 Answers   Clover, HCL,


What is the implicit name and type of the parameter that gets passed into the class set method?

1 Answers  


localization using windows c#

2 Answers  


How do you comment out code in c#?

1 Answers  


Is there hashmap in c#?

1 Answers  


why we can't create an object for a static class?? what is the reason behind this?

4 Answers   HCL,


What is Serialization and how do we implement (in real time scenario)

1 Answers  


What is eager and lazy loading in c#?

1 Answers  


What is cosole application?

1 Answers  


Categories