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 MyInterfaceImpl implements MyInterface { | |
@Override public void method1() { | |
System.out.println("Implementation of method 1"); | |
} | |
@Override public void method2() { | |
System.out.println("Implementation of method 2"); | |
} | |
public static void main(String[] args){ |
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
Implementation of method 1 | |
Implementation of method 2 |
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
Implementation of method 1 | |
Implementation of method 2 |
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 interface MyInterface { | |
/** | |
* All the methods of an interface are public by default | |
*/ | |
void method1(); | |
void method2(); | |
default void newMethod(){ | |
System.out.println("This is the default implementation of the method"); | |
} | |
} |
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 MyInterfaceImpl implements MyInterface { | |
@Override public void method1() { | |
System.out.println("Implementation of method 1"); | |
} | |
@Override public void method2() { | |
System.out.println("Implementation of method 2"); | |
} | |
public static void main(String[] args){ |
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
Implementation of method 1 | |
Implementation of method 2 | |
This is the default implementation of the method |
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 interface InterfaceA { | |
default void method(){ | |
System.out.println("Interface A default method"); | |
} | |
} |
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 interface InterfaceB { | |
default void method(){ | |
System.out.println("Interface A default method"); | |
} | |
} |
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 InterfaceImpl implements InterfaceA,InterfaceB{ | |
} |
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 InterfaceImpl implements InterfaceA,InterfaceB{ | |
@Override public void method() { | |
System.out.println("Default method in implementation class"); | |
} | |
public static void main(String[] args){ | |
InterfaceA obj = new InterfaceImpl(); | |
obj.method(); | |
} | |
} |