40.sealed method, it cannot be overridden.
/*
If you create a sealed class, it cannot be derived. If you create a sealed method, it cannot be overridden.
Local variables can't be sealed.
The sealed method in C# cannot be overridden further. It must be used with override keyword in method.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sealed_method.cs
{
class Base
{
public virtual string display()
{
return "Base class method";
}
}
class Derived : Base
{
public sealed override string display()
{
return "sealed mehtod of Derived class";
}
}
class Program
{
static void Main(string[] args)
{
Derived obj = new Derived();
Console.WriteLine( obj.display());
Console.Read();
}
}
}
Comments
Post a Comment