Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Program 1
class TestMyThread
{
public static void main(String args[]) throws Exception
{
Runnable r1=()->{
try
{
for(int i=1;i<=10;i++)
{
System.out.println("This is child Thread ");
Thread.sleep(1000);
}
}
catch(Exception e)
{}
};
Thread t1=new Thread(r1);
t1.start();
for(int i=1;i<=10;i++)
{
System.out.println("This is Main Thread ");
Thread.sleep(1000);
}
}
}
// class MyThread implements Runnable
// {
// public void run()
// {
// try
// {
// for(int i=1;i<=10;i++)
// {
// System.out.println("This is child Thread ");
// Thread.sleep(1000);
// }
// }
// catch(Exception e)
// {
// }
// }
// }
// class TestMyThread
// {
// public static void main(String args[]) throws Exception
// {
// MyThread M1=new MyThread();
// Thread T1=new Thread(M1);
// T1.start();
// for(int i=1;i<=10;i++)
// {
// System.out.println("This is Main Thread ");
// Thread.sleep(1000);
// }
// }
// }