I have a doubt regarding interfaces. An abstract class with all the methods declared abstract is same as an interface. i.e; the concrete class which extends the abstract class or the one implementing the interface should define all the methods. This is fine. So Is the only advantage of interfaces is Multiple inheritance ? Or is there any other ? Can anyone explain.
Joined: Aug 08, 2007
Yes. there is one advantage. do you have Multiple inheritance of interface but not can have Multiple inheritance of class. example:
Interfaces allow you to define common behavior among otherwise very different objects; like sailboats and ducks.
A sailboat object could be a subclass of Boat, and a duck could be a subclass of Bird. Even though they are completely different objects, they have some common traits.
They can both float and they both have the means to move in the water; one with sails and the other with webbed feet. So even though they are radically different objects, a method that operates on a Floatable, can expect that it will float and has a propel method.