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; }
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.
2nd example :
Below program will not run as Test class is sealed which cannot be inherit.