Categories

Jan 20 in C Sharp (C#)
Q: What is a Sealed class in C#?

1 Answer

Jan 20

A Sealed class is a class which cannot be inherited. The sealed keyword is used to prohibit inheritance of a particular class in C#.

A sealed class can be public as well as private.

Example:

public sealed class A

{

    public void Fun()

    {

    }

}

//Compiler Error: 'B': cannot derive from sealed type 'A'

public class B : A

{

    public static void Fun()

    {

    }

}

public class C

{

    public static void Fun()

    {

        //Valid

        A a = new A();

        a.Fun();

    }

}

Click here to read more about C Sharp
Click here to read more about Insurance

Related questions

Madanswer
May 6 in C Sharp (C#)
Oct 18, 2019 in C Sharp (C#)
Jun 16 in C Sharp (C#)
...