To implement name hiding with interface inheritance. Aim is to create an interface IMario with a method Ability(). Implement this interface in a class Mario and override the Ability() method also to create another class SuperMario that inherits from Mario and hides the Ability() method using the new keyword.
Create interface IMario with method Ability for Mario classes.
Mario class implements IMario, defines virtual Ability method.
SuperMario extends Mario, overrides Ability method with new.
Instantiate SuperMario and Mario, call Ability on each.
SuperMario's Ability prints "This is inside SuperMario", Mario's prints "This is inside Mario".
#### Name : Shyam Kumar A
#### Reg No: 212221230098
using System;
public interface IMario
{
void Ability();
}
class Mario:IMario{
public virtual void Ability()
{
Console.WriteLine("Mario's Ability:Normal Dancing");
}
}
class SuperMario:Mario
{
public new void Ability()
{
Console.WriteLine("Mario's Ability:Super Dancing");
}
}
class Program
{
static void Main(string[]args)
{
IMario mario=new Mario();
SuperMario superMario=new SuperMario();
mario.Ability();
superMario.Ability();
}
}
Thus, the program has been executed successfully.