---
title: "How to use Sealed classes in the c# program?"  
description: "How to use Sealed classes in the c# program?"  
author: "Barbara Jones"  
published: 2016-09-14  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/23040/how-to-use-sealed-classes-in-the-c-sharp-program  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to use Sealed classes in the c# program?

If we use Sealed classes in the program, then we can't inherit it.

In C#, the sealed modifier is used to define a class as sealed.

Below are two examples where we can use sealed key word for the class :

1st example

Below program will run successfully even after using the sealed keyword.

\

```
using System;sealed class Restclass{    public int
Add(int x, int y)    {        return x +
y;    }}class program{    static void
Main(string[] args)    {        Restclass
implecls = new Restclass();        int total =
implecls.Add(4, 5);       
Console.WriteLine("Total = {0} " ,total);       
Console.ReadLine();    }}
```

**2nd example :**

Below program will not run as Test class is sealed which cannot be inherit.

```
Public sealed class Test{public int Number;public string Name;} Public sealed class child1:Test{public string Name;} 
```

## Answers

### Answer by Barbara Jones

If we use Sealed classes in the program, then we can't inherit it.

In C#, the sealed modifier is used to define a class as sealed.

Below are two examples where we can use sealed key word for the class :

1st example

Below program will run successfully even after using the sealed keyword.

\

```
using System;sealed class Restclass{    public int
Add(int x, int y)    {        return x +
y;    }}class program{    static void
Main(string[] args)    {        Restclass
implecls = new Restclass();        int total =
implecls.Add(4, 5);       
Console.WriteLine("Total = {0} " ,total);       
Console.ReadLine();    }}
```

**2nd example :**

Below program will not run as Test class is sealed which cannot be inherit.

```
Public sealed class Test{public int Number;public string Name;} Public sealed class child1:Test{public string Name;} 
```


---

Original Source: https://www.mindstick.com/interview/23040/how-to-use-sealed-classes-in-the-c-sharp-program

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
