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
How do I trim a space in c#?
What is a generic method?
What is inner class in c#?
Why abstract class can not be instantiated?
Why reflection is used in c#?
What is meant by clr?
what are the contents of an assembly ?
What is use of FormBoarderStyle Propertie
What is difference between an Structure and Class?
What is msil in c#?
hi, is compulsory .net knowledge need for biztalk server training. if need, how far?.tell me some info abt real time instructors in hyd or other?
What are examples of desktop applications?
What are the advantages of constructor?
What do you understand by 'access specifiers' in C#?
What is difference between array and list in c#?