+ 7

Can you give an example how to implement muliple interfaces in one class?

23rd Feb 2016, 4:20 PM
Andrzej Warunek
2 Answers
+ 9
one example that occurs to me is: imagine a class "horse". it is an animal, so it could extend the interface "animal" with its own implementation of how it behaves as an animal, but you could also think of it as a mean of transportation, so it could also extend the interface "meanoftransport". it is done like this: class horse implements animal, meanoftransport{ //methods of both interfaces } not every animal serves as transport, therefore they do not all implement the meanoftransport interface, like dog or cat. and not all classes that implement meansoftransport are animals, like car and bus. so you have a way of associating classes that represent completely different objects but have one characteristic in common. i am still struggling with the concept of interface myself, but from reading many posts i see that is what it is used for. there is a tendency of leaving aside the inheritance and preferring implementation of ineterfaces. hoped it helped...
16th Mar 2016, 6:25 PM
Leonardo Paschoal
Leonardo Paschoal - avatar
+ 4
Yes you can do that like If my class name is mahi and I just want to implement actionListener, keyListener Then I have to write class Mahi extends Frame implements actionListener, keyListener So simple
28th Nov 2016, 7:43 AM
Mahipal Jat
Mahipal Jat - avatar