How to use Method Overriding in C# .Net?
Creating a method in derived class with same signature as a method in base class is called as method overriding.Same signature means methods must have same name, same number of arguments and same type of arguments.
Method overriding is possible only in derived classes, but not within the same class.
When derived class needs a method with same signature as in base class, but wants to execute different code than provided by base class then method overriding will be used.
Example
using System;
namespace methodoverriding
{
class BaseClass
{
public virtual string YourCountry()
{
return "India";
}
}
class DerivedClass : BaseClass
{
public override string YourCountry()
{
return "USA";
}
}
class Program
{
static void Main(string[] args)
{
DerivedClass obj = new DerivedClass();
string Country = YourCountry();
Console.WriteLine(Country);
Console.Read();
}
}
}
Output
USA
Awesome, tutorial thank you, also i want to share How to Enable Visual Editor in Wordpress
ReplyDeleteThank you for sharing this indispensable information about Microsoft's one of the greatest technologies, ASP.NET. If you want to have a job in ASP.NET with high salary then consider getting certification.
ReplyDeleteBest Regards,
Crish Watson
Pass Microsoft Certification Without Taking Exam
Very Good... You give very informative tutorial of c#.NEt.
ReplyDeleteAlso hire a dedicated dot net developer for more information.
I really enjoy your blog it's a nice post
ReplyDeleteDot Net Online Training
Visit us: Dot Net Online Training
ccnp certification without exam
ReplyDeleteccie enterprise infrastructure certification online
nclex certification online
cisa certification without test online
cism certification without test online
cgeit certification without exam online
crisc certification without exam online
OSED certification without exam.
ReplyDeleteOSWE certification without exam
osep certificate without exam
OSWP certificate without exam
OSCE online without exam
OSCP certificate without exam online