I have just started with JAVA 1.8 version and had a question while going through the tutorials regarding lambda expression.
Can we have more than 1 implementation(lambda expression) for the abstract method by creating multiple instances of the Interface WITHIN THE SAME CLASS??? I tried the code and it ran perfectly....
Now my question is that the very concept of interface is that every IMPLEMENTING CLASS WILL HAVE A DEFINITION FOR THE ABSTRACT METHOD. THEN HOW CAN WE HAVE TWO METHOD BODIES(lambda expressions) in the SAME CLASS ???
Consider the below code :
public static void main(String[] args) {
Interf i = (a, b) -> a + b;
System.out.println("The result is >> " + i.result(10, 20));
Interf i1 = (a, b) -> a - b;
System.out.println("The result is >> " + i1.result(10, 20));
}
Output:
The result is >> 30
The result is >> -10