The implements keyword in Java language
- Home
- Keyword in Java
- The implements keyword in Java language
- On
- By
- 0 Comment
- Categories: Keyword in Java
The implements keyword in Java language
The implements keyword in Java language
In this tutorial, we will discuss about The implements keyword in Java language
The Java language implements keyword is using to implement basic concrete of method definition in an interface. The implemented class must provide concrete implementation for the method definition by the interface if not the class must be abstract.
The following example explains how to implement a class using interface and provide details of implementation for the interface’s methods
Syntax
interface <interface_name>{ public void method1(); //method definition_1 No declaration inside interface public void method2(); //method definition_1 No declaration inside interface } class <Class_name> implements <interface_name> public void method1(){ //method 1 implementation } public void method2(){ //method2 implementation } }
Example
Interface School{ void beginning(); //unimplemented methods void ending(); } class student implements school{ void beginning(){ // beginning of the school} //implements here void ending(){ //Ending of the school } }
a class can implement multiple interface. the interface names are separated by commas
Example is given below
interface school{} //interface_one interface teacher{} //interface_two class student implements school,teacher{}
This is a single class implements by multiple interfaces
There are other Java language keywords that are similar to this keyword
static keyword in Java language
Suggested for you
Usage of final keyword in Java