Professional Documents
Culture Documents
Sealed Class
Sealed Class
Sealed Class
Method Overriding
What is Sealed Class ???
• sealed keyword applies restrictions on the class and method.
• The keyword tells the compiler that the class is sealed, and
therefore, cannot be extended.
• The following is the syntax and Example of a sealed class :
2. public override int myValue()
{
-
-
-
}
3. base.myValue();
Example
using System;
class baseClass
{
public virtual void Greetings()
{ Console.WriteLine("baseClass Saying Hello!"); }
}
class subClass : baseClass
{
public override void Greetings()
{
base.Greetings();
Console.WriteLine("subClass Saying Hello!");
}
}
class Program
{
static void Main()
{
baseClass obj1 = new subClass();
obj1.Greetings();
Console.ReadLine();
}
}