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 a method return multiple values in c#?
What is expression tree with example?
What is marshalling in c#?
How can you access a private method of a class?
Does google use c#?
Can list contain duplicates c#?
Explain polymorphism in c# with a simple example?
What is the c# equivalent of c++ catch (…), which was a catch-all statement for any possible exception? Does c# support try-catch-finally blocks?
Explain the functionalities of satellite assembly?
Explain what a diffgram, and a good use for one Define diffgram? How it be used?
How do generics work in c#?
What are the steps to make an assembly to public?
Can a loop recorder detect a heart attack?
What are the concepts of dispose method?
Explain About web methods and its various attributes