Write a program to implement the concept of threading by implementing Runnable Interface

 

class tclassp implements Runnable
{
public void run()
{
for(int i=1;i<5;i++)
{
System.out.println("From thread p:"+i);
}
System.out.println("Thread p halts now");
}
}
class rundemo
{
public static void main(String args[])
{
tclassp tp=new tclassp();
Thread trp=new Thread(tp);
trp.start();
System.out.println("End of main thread");
}
}

 

 

Output:
C:\>java rundemo
End of main thread
From thread p:1
From thread p:2
From thread p:3
From thread p:4
Thread p halts now

C:\>