JP-4
Creating Threads
Code:
public class StartExp1 extends Thread
{
public void run()
{
for(i=0;i<=6;i++)
{
System.out.println(i);
}
}
public static void main(String[] args)
{
StartExp1 t1= new StartExp1();
t1.start();
}
}
Output:
By implementing Runnable Interface
Code:
public class StartExp2 implements Runnable
{
public void run()
{
System.out.println("Threading is running...");
}
public static void main(String[] args)
{
StartExp2 m1= new StartExp2();
Thread t1= new Thread(m1);
t1.start();
}
}
Output:
Comments
Post a Comment