When we create a class that uses an interface, we use the keyword implements and the interface name in the class header. Interface provides an empty method header without any instruction within that method and it is the class which implements that interface responsibility to include instructions for that method. In below program I will show you how to write a simple class which implements an interface. First let us create an interface file.
public interface SingSongs {
public void sing();
}
Then create a class which will implement this interface with the interface method that print a line of output on the screen.
public class SingingBoy implements SingSongs {
public void sing() {
System.out.println("I am a real singing boy!");
}
}
Finally create a new instance of the above class and use that class method.
public class RealBoySings {
public static void main(String[] args) {
SingingBoy boy = new SingingBoy();
boy.sing();
}
}
Run the last java file and you should get below outcome:

Next Page :
Javascript replace method reviewJavascript replace method review
How to use Java Scanner ClassThis article will show you how to use Java Scanner Class with simple Java code.
Show text on JFrame with Java programShow text on JFrame with Java program!
The if…else statement in Java program‘The if…else statement in Java program’ article will show you an example to use the statement.
Java Scanner ClassJava Scanner class tutorial will show you how to create an instance of the scanner class and read in the input from the user then print out the sum of those inputs.
Create a simple Java methodAn article about how to create a simple Java method.
