C# method overriding tutorial example explained
#C# #method #override
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args) {
//method overriding = provides a new version of a method inherited from a parent class
// inherited method must be: abstract, virtual, or already overriden
// Used with ToString(), polymorphism
Dog dog = new Dog();
Cat cat = new Cat();
dog.Speak();
cat.Speak();
Console.ReadKey();
}
}
class Animal
{
public virtual void Speak()
{
Console.WriteLine("The animal goes *brrr*");
}
}
class Dog : Animal
{
public override void Speak()
{
Console.WriteLine("The dog goes *woof*");
}
}
class Cat : Animal
{
}
}
Watch video C# method overriding 🙅 online, duration hours minute second in high quality that is uploaded to the channel Bro Code 03 July 2021. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 45,243 times and liked it 1.5 thousand visitors.