Explicit Interface
Wed Oct 29 2025 17:16:54 GMT+0000 (Coordinated Universal Time)
Saved by
@vplab
interface Animal
{
void Speak();
}
interface Mammal : Animal
{
void Walk();
}
class Dog : Mammal
{
void Animal.Speak()
{
Console.WriteLine("Woof!");
}
void Mammal.Walk()
{
Console.WriteLine("The dog is walking.");
}
public void Eat()
{
Console.WriteLine("The dog is eating.");
}
}
class Program
{
static void Main(string[] args)
{
Dog d = new Dog();
d.Eat();
Animal a = d;
a.Speak();
Mammal m = d;
m.Walk();
}
}
content_copyCOPY
Comments