If a class is declared as Sealed we can not inherit the class the within the class and outside the class also.
Loading
If a class is declared as Sealed we can not inherit the class the within the class and outside the class also.
In simple things, Sealed means you can not use this class as a base class. You can create instance of this class and access properties and methods.
using System;public class Program{public static void Main(){ExampleCls example = new ExampleCls();example.num = 5;Console.WriteLine(example.num);Console.ReadLine();}}public sealed class ExampleCls{public int num { get; set; }public string data { get; set; }}//You can not use as base class like belowpublic class ExampleCls2 : ExampleCls{public int num2 { get; set; }public string data2 { get; set; }}
In C#.Net, The purpose of Sealed class is to restrict the Inheritance functionality of OOPS.
If we name a class as sealed class,it cannot be inherited.
Syntax: sealed class MyClass