Let's say we have two classes, Tiger
and Aeroplane
.
One thing in common for these two types is the Speed. I know that it would be illogical to create a superclass ClassWithSpeed
and then derive subclasses Aeroplane
and Tiger
from it.
Instead, it is better to create an interface that contains the method speed()
and then implement it in Aeroplane
and Tiger
. I get that. But, we can do the same thing without interfaces. We could define method speed()
in Aeroplane
and method speed()
in Tiger
.
The only (maybe very big) flaw it would be that we couldn't "reach" the objects of Tiger
and Aeroplane
through an interface reference.
I am beginner in Java and OOP, and I would be very grateful if someone explained to me the role of interfaces. Cheers!