A independent task in Thread-based Multitasking is called a Thread.
We can define a Thread in the following two ways:
(a) By extending Thread class
(b) By implementing Runnable interface.
We can define a Thread in the following two ways:
(a) By extending Thread class
(b) By implementing Runnable interface.
(a) By extending Thread class
class myThread extends Thread
{
public
void run()
{
for(int
i=1; i<=10; i++)
{
System.out.println("Child
thread is running ");
}
}
}
class ThreadExtend
{
public
static void main(String args[]) throws InterruptedException
{
myThread
t = new myThread();
t.start();
for(int
i=1; i<=10;i++)
{
System.out.println("Main
thread ");
}
}
}
Output: