Java Implements

Java Implements

In Java implements is a keyword. Where to use implements keyword in Java coding? We know Java does not support multiple inheritance. That is, one class cannot extend or inherit two classes. That is, following code does not work.

class Bird { }
class Animal { }
public class Ostrich extends Bird, Animal { }

Infact, not supporting mmltiple inheritance is a drawback of Java. Just to support multiple inheritance, Java introduced interfaces. One property of interface is it should have all abstract methods. Any class would like to inherit the interface, should use implements keyword instead of general extends keyword. Now let us see how to use Java implements keyword with interfaces.

Example on Java implements

Java implements
Output screenshot of Java implements

Observe, in the above code, Ostrich inherits two interfaces using implements keyword and not extends. After Java implements there should be interfaces only of any number.

To know more on inheritance with interfaces and a table on extends vs implements refer Java Multiple Interfaces Inheritance.

Leave a Reply

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