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
Can we extend static class in c#?
Explain how obfuscator works in .net
Which framework is best for desktop application?
What is Fragmentation and its Types?
What is the difference between do and while loop?
What is better C# or VB.NET?
Can we override constructor in c#?
Why do we need generics in c#?
What are the properties of string?
What is remote data?
What's c# ?
Why is xml called extensible?
Can datetime be null c#?
Explain the functionalities of satellite assembly?
What is the difference between ref and out in c#?