+1 vote
in C Sharp by
What is a Sealed class in C#?

1 Answer

0 votes
by

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();

    }

}

Related questions

0 votes
asked Feb 16, 2020 in C Sharp by rahuljain1
+1 vote
+1 vote
asked Jan 20, 2020 in C Sharp by AdilsonLima
...