Interface :
It is similar to a class in java, instead, with a keyword as interface.
Interface used as method declaration, not for implementation untill jdk7
Eg:
1 2 3 4 5 6 7 8 9 10 | Public interface MyInteface { Void m1(String str); Void m2(int i); // But you cannot write as follows in interface /*Void m3(String s){ System.out.println("You cannot write this way. "); }*/ } |
Interface in Java-8 :
Java-8 interface can have STATIC & DEFAULT methods, we can also have method implementation from jdk 8 but has to be default
Eg: Before JAVA-8
1 2 3 4 5 6 7 | Public interface MyInterface{ Void m1(String str); /* Default void m2(String str){ System.out.println(“Gives an error in prior jav-8 versions. ”); } //Gives you an error */ } |