# Sealed Class in C\#

### &#x20;What is the main purpose of Sealed Class? \&#xNAN;***Sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as a sealed class, this class cannot be inherited.***&#x20;

```
using System;  
class Class1  
{  
    static void Main(string[] args)  
    {  
        SealedClass sealedCls = new SealedClass();  
        int total = sealedCls.Add(4, 5);  
        Console.WriteLine("Total = " + total.ToString());  
    }  
}  
// Sealed class  
sealed class SealedClass  
{  
    public int Add(int x, int y)  
    {  
        return x + y;  
    }  
}   
```

### Why Sealed Classes?

We just saw how to create and use a sealed class in C#. The main purpose of a sealed class is to take away the inheritance feature from the class users so they cannot derive a class from it. One of the best usage of sealed classes is when you have a class with static members.

reference : c-sharpcorner.com\Mahes Chand&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hsnaltan13.gitbook.io/object-oriented-programming/sealed-class-in-c.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
