why can a class implement multiple interfaces?

user1664427 picture user1664427 · May 29, 2013 · Viewed 8.7k times · Source

This is the only question about interfaces in oop I can't seem to fully explain. So again, why in oop can a class implement multiple interfaces?

If you can provide a few examples that would be great. thanks in advance.

Answer

Mingyu picture Mingyu · May 29, 2013

Conceptual Example

The way I think about the multiple interfaces is interface is like the verb or adjective, and class is like the subject.

A tiger can run, so the Tiger class may implement Runnable Interface.

A tiger can eat, so the Tiger class may implement Eatable Interface.

Because an instance of the class could have different behaviors, we could have different corresponding interfaces.

Realistic Example

java.util Class HashMap<K,V>

It implements Serializable, Cloneable, Map<K,V>

All of the interfaces are the characteristics of Class HashMap.