.NET FAQs Unleashed!
 
    
    

How to prevent a class from being inherited? Sealed in C#?

In order to prevent a class in C# from being inherited, the sealed keyword is used. Thus a sealed class may not serve as a base class of any other class. It is also obvious that a sealed class cannot be an abstract class. Code below...

C# Example
sealed class ClassA
{
public int x;
public int y;
}

No class can inherit from ClassA defined above. Instances of ClassA may be created and its members may then be accessed, but nothing like the code below is possible...

class DerivedClass: ClassA {} // Error

To know whats a sealed method in C# Click Here

Protected Internal  Array  Sort Array  Throw  Multiple Catch  Polymorphism  Inheritance  Session Viewstate  Autogenerate  ReadOnly  Sealed Class  Sealed Method  Multiple Interfaces  Overloading  Overloaded Constructors  Generics  Main  Case Sensitive  Console  Specifier  Return Type  SetCommandLineArgs  System Environment  New  Default Values of Types Compiler Error Constant Variable Const Const - ReadOnly Parameter Modifier Out Ref Interface Interface Reference, is, as System.Collection

More Interview Questions...