Created
September 3, 2017 17:05
-
-
Save LazaroIbanez/d2981bf1bddbb1ca2d6013398b8a06a4 to your computer and use it in GitHub Desktop.
Java interface static method is similar to default method except that we can’t override them in the implementation classes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class E implements Interf1 { | |
public String getId() { | |
return “E: get Id”; | |
} | |
public String getOtherId() { | |
return “E: get Other Id”; | |
} | |
public static void main (String… args) { | |
System.out.println(“Object 1”); | |
E object1 = new E(); | |
System.out.println(object1.getId()); | |
System.out.println(object1.getOtherId()); | |
System.out.println(“Object 2”); | |
Interf1 object2 = new E(); | |
System.out.println(object2.getId()); | |
System.out.println(“Calling the static method in Interf1”); | |
System.out.println(Interf1.getOtherId()); | |
} | |
} | |
interface Interf1 { | |
public default String getId() { | |
return “Interface 1: get Id”; | |
} | |
public static String getOtherId() { | |
return “Interface 1: get Other Id”; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment