Multiple Interfaces Implements Java

Multiple Interfaces Implements Java


Summary: At the end of this tutorial, you will be comfortable with Multiple Interfaces Implements usage. Looks difficult at the beginning, but put some patience and start reading. Do some small programs to understand still better. This is required for a Developer. Any doubts may be forwarded to me.

As Java does not support direct multiple inheritance, it introduced interfaces to support partial utility of multiple inheritance. For inheriting multiple interfaces one more keyword (apart "extends") used is "implements".

Let us list some rules which are already stated in "Extends Implements" topic. Take some classes and interfaces.

Rules of Java inheritance

1. After extends there must be only one class either concrete (non-abstract) or abstract.
2. After implements there can be any number of interfaces.
3. One interface can extend any number of interfaces.

Let us see the coding for the above rules.

class A { }
class B { }
interface C { }
interface D { }
interface E { }

Let us see the combinations of the above.

1st option (it is valid)

class A extends B implements C, D, E

2nd option (it is valid)

interface C extends D

3rd option (it is valid)

interface C extends D, E

Observe, after extends more than one interface.

4th option (it is valid), Java multiple extends

interface C extends D, E
class A implements C

5th option (it is valid)

interface C extends D, E
class A extends B implements C

Java extends vs implements

Even though the keywords "extends" and "implements" are used with inheritance, they differ a lot in their usage.

Extends Implements
Does not support multiple inheritance Supports multiple inheritance
Used with concrete and abstract classes Used with interfaces only
After extends only one class should come After implements many interfaces can come

Pass your comments to improve the quality of this tutorial "Multiple Interfaces Implements".

Leave a Reply

Your email address will not be published. Required fields are marked *