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
{
}
Example
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;
}
}
No comments:
Post a Comment