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; }
Liked By
Write Answer
How to use Sealed classes in the c# program?
Join MindStick Community
You have need login or register for voting of answers or question.
Barbara Jones
14-Sep-2016If 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.
2nd example :
Below program will not run as Test class is sealed which cannot be inherit.