Java implements | Interface | keyword | Example code

Java Implements keyword is for implementing an interface. This keyword comes to solve Multiple Inheritance problems in java. If you want a inherit many classes by a single one, this is not possible with extends the class.  You need to define an Interface and then use Java Implements to inherit multiple Interface properties.

Java implements Interface keyword Example

In this tutorial we will learn about Java implements Interface with examples. But before the start, you must have basic knowledge about Interface, class, and Inheritance. Here is a link to it.

Implements: You are implementing a contract. The class implementing the interface “has a” capability.

Syntax

Here is the simple syntax of how to use implements.

Java implements an example

Here is an example of how java implements the interface. In the code, we created a one interface Add and class Hello inherit method by using implements.

Output: Addition of number is 7

Question: How to Java implements multiple interfaces?

Answer: Same as the Above example we can do multiple interfaces implement in class. Below an example of inheriting methods from 2 Interfaces.

Note: A interface can have default methods in the interface, this is updated in Java 8 release.

Output: Addition of number is 7
Multiplication of number is 12

Question: Can Java implements class?

Answer: no, Java can’t implement class they can extend the class.

For more about this topic must read the above-mentioned tutorial link. This is a very important chapter for coding and interview perspective. Do comment doubt and suggestions.

Do comment if you have any doubts and suggestions this topic.

Note: This example (Project) is developed in IntelliJ IDEA 2018.2.6 (Community Edition)
JRE: 11.0.1
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.1

Java version 11

All Java extends class is in Java 11, so it may change on different from Java 9 or 10 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.