What are Sealed Classes in C#?

Answer Posted / saba

Sealed classes are used to restrict the inheritance feature
of object oriented programming. Once a class is defined as
sealed class, this class cannot be inherited.

The following class definition defines a sealed class in C#:


// Sealed class

sealed class SealedClass

{

}

In the following code, I create a sealed class SealedClass
and use it from Class1. If you run this code, it will work
fine. But if you try to derive a class from sealed class,
you will get an error.


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

sealed class SealedClass

{

public int Add(int x, int y)

{

return x + y;

}

}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the features of an abstract class in net.

509


Explain the difference between Response.Write () and Response.Output.Write ().

530


What is a static in c#?

496


What is assembly manifest?

530


Is string value type c#?

492






What is the difference between static and private constructor?

478


What's the difference between abstraction and encapsulation?

467


What is ControlBox Propertie

577


I have 3 overloaded constructors in my class. In order to avoid making instance of the class do I need to make all constructors to private?

554


Differentiate between response.expires and response.expiresabsolute?

552


What is private constructor c#?

502


Is dictionary a collection?

474


What is the diff between the System.Array.CopyTo() and System.Array.Clone()?

551


What is difference between function and method in c#?

464


How to create multi-dimensional array?

603