Anonymous class and Lambda expression

 package com.company;

interface myInterface{
void meth1(int x);
// void meth2();
}
//class hell implements i{
// public void meth1(){
// System.out.println("Hello my name is rohan");
// }
// public void meth2(){
// System.out.println("Hello, i am son of Rohan");
// }
//}
public class CWH_109_LambdaExpression {
public static void main(String[] args) {
// Anonymous class
// i obj = new i() {
// @Override
// public void meth1() {
// System.out.println("Hello my name is rohan1111");
// }
// @Override
// public void meth2() {
// System.out.println("Hello my name is rohan2222");
// }
// };
// obj.meth2();
// i obj1= new i() {
// @Override
// public void meth1() {
// }
// @Override
// public void meth2() {
//
// }
// };
// Lambda expression

myInterface obj= (x)->{System.out.println("I am a method of a class which implementing myInterface 'Interface' "+ x);};
obj.meth1(56);
}
}

Comments