Wednesday, February 25, 2009

source code to create thread by extending thread class



package threads;
public class MyThread extends Thread
{
public void run()
{
System.out.println("child job");
}
}
/*Here run method is the heart of thread
where you have to define the job.*/
class Mysample
{
public static void main(String arr[])
{
MyThread t=new MyThread();
t.start(); //starting a thread
System.out.println("Main thread job");
}
}

output:
Main thread job
child job



0 comments:

Post a Comment