Java Method Reference in Multithreading
Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Program 1
//Method reference using static method
interface MyInterface1
{
public void display();
}
class Test
{
public static testShow()
{
System.out.println("Hello This is Test Show Method of Test Class");
}
}
class TestMethodReference
{
public static void main(String args[])
{
MyInterface1 M=Test::testShow;
M.display();
}
}
// class Test1
// {
// public static void testShow1(int n)
// {
// System.out.println("Hello This is Test Show Method of Test1 Class Bye Bye");
// }
// }
// MyInterface1 M1=Test1::testShow1;
// M1.display();Program 2
//Method reference using instance
interface MyInterface2
{
void display();
}
class Test2
{
public void testshow2()
{
System.out.println("This is test show 2 method of Test 2 class");
}
}
class TestMethodReference1
{
public static void main(String args[])
{
Test2 t1=new Test2();
MyInterface2 M1=t1::testshow2;
M1.display();
}
}Program 3
interface MyButton
{
void myClick();
}
class MyColor
{
public static void colorchange()
{
System.out.println("Now Color is red .... Thanks");
}
}
class MyPhoto
{
public static void photochange()
{
System.out.println("Now This is My Photo .... Thanks Bye Bye");
}
}
class TestButton
{
public static void main(String args[])
{
MyButton B1=MyColor::colorchange;
B1.myClick();
MyButton B2=MyPhoto::photochange;
B2.myClick();
}
} We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

