Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
interface InterfaceExample { public void sayHello(); } public class Main implements InterfaceExample{ public void sayHello() { System.out.println("Hello Welcome !"); } public static void main(String args[]) { Main example = new Main(); example.sayHello(); } } |
Output:
1 2 3 |
Hello Welcome ! |
Interface looks like class but it is not a class.
An interface can have methods and variables just like the class but the methods declared in interface are by default abstract (only method signature, no body).