Extension Method of Java
Hello Friends
Here is the example
- interface MyInterface {
- String enter(String name);
- default String exit(String name) {
- return“ Hello” + name + ”, you are using exit method of MyInterface interface”;
- }
- }
- public class MyClass {
- public static void main(String[] args) {
- MyInterface f1 = new MyInterface() {
- @Override
- public String enter(String name) {
- return“ Hello” + name + ”, you are using enter method of MyInterface interface”;
- }
- };
- System.out.println(f1.enter(“Aman”));
- System.out.println(f1.exit(“Aman”));
- }
- }
Output
Hello Aman, you are using the enter method of MyInterface interface.
Hello Aman, you are using exit method of MyInterface interface