What is the sealed class?

Om ji mishra

Total Post:17

Points:119

Posted by  Om ji mishra
C#
 1085  View(s)
Ratings:
Rate this:

What is the sealed class?        

  1. Re: What is the sealed class?

    When we create a sealed class then we cannot inherit that class with any derived class. It is created when we want to restrict the class from being inherited. if we use a shield class with any derived class then the compiler will throw an error. We can use the property of a sealed class in any other class by creating an object.

    Code:-
    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 SealedClass
    {
      public int Add(int x, int y)
        {
          return x + y;
        }
    }
    Output:- 
    Total = 9

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.