Java Lab Programs (49) Functional Interface
Java Lab Programs (49) Functional Interface
• Functional Interface in Java is also called Single Abstract Method (SAM) Interface.
• From Java8 onwards, to represent the instance of functional interfaces, lambda
expressions are used. It is a new feature in Java, which helps to achieve functional
programming approach.
• Lambda expressions are anonymous (don’t have names) shortcode blocks that can
take parameters and return a value just like methods.
public static void main(String a[]) public static void main(String a[])
{ {
abc a1=new abc(); abc a1=new abc();
a1.javaclass("Java SE11"); a1.javaclass("Java SE11");
}
}
@FunctionalInterface @FunctionalInterface
interface rcat interface rcat
{ {
void javaclass(String stu); void javaclass(String stu);
} void javaquiz(String a);
}
class abc implements rcat
{ class abc implements rcat
public void javaclass(String stu) {
{ public void javaclass(String stu)
System.out.println(stu); {
} System.out.println(stu);
}
public static void main(String a[])
{ public static void main(String a[])
abc a1=new abc(); {
a1.javaclass("Java SE11"); abc a1=new abc();
a1.javaclass("Java SE11");
rcat r1=new abc();
r1.javaclass("Oracle Certified"); rcat r1=new abc();
r1.javaclass("Oracle Certified");
}
} }
}