0
Completed
Question on book <Dive into Design Patterns>, Inheritance
On page 19, if a superclass implements an interface, all of its subclasses must also implement it
I don't understand it. For example, The below C# sample code I wrote, it has no compile error.
Bird "superclass, implement the Ifly"
Duck "subclass of Bird, but have not implement the Ifly"
Am I mis-understand it?
var duck = new Duck();
duck.Flying(4);
interface Ifly
{
void Flying(int distance);
}
abstract class Bird : Ifly
{
public void Flying(int distance)
{
Console.WriteLine($"I am flying {distance} miles!");
}
}
class Duck : Bird
{}
-- Jasper
I don't understand it. For example, The below C# sample code I wrote, it has no compile error.
Bird "superclass, implement the Ifly"
Duck "subclass of Bird, but have not implement the Ifly"
Am I mis-understand it?
var duck = new Duck();
duck.Flying(4);
interface Ifly
{
void Flying(int distance);
}
abstract class Bird : Ifly
{
public void Flying(int distance)
{
Console.WriteLine($"I am flying {distance} miles!");
}
}
class Duck : Bird
{}
-- Jasper
Customer support service by UserEcho
Hi!
Sorry for the confusion. I mean that all the subclasses already implement it implicitly if the superclass implements it explicitly. In other words, you can't refuse to have some parts of the original interface in a subclass, it already implements it and you can't change that.