Many time we asked question in an interview of lambda expression.
Get little bit confused.
How to explain him? Even though I knew how it is working.
Don't worry this is how you can explain :
Lambda expression can be used for functional interface.
Functional interface is kind of interface having only one method.
Ex.
Interface FunInterface
{
public void seeLambda();
}
class LamabEx{
public static void main(String args[]){
int car = 4;
// Lambda Expression
FunInterface obj = ()->{ System.out.println(" I have number of cars are "+ car) } ;
obj.seeLambda();
}
}
Output :{
public void seeLambda();
}
class LamabEx{
public static void main(String args[]){
int car = 4;
// Lambda Expression
FunInterface obj = ()->{ System.out.println(" I have number of cars are "+ car) } ;
obj.seeLambda();
}
}
I have number of cars are 4

No comments