Java Program to create thread by implementing runnable interface
Program
class RunnableThread implements Runnable
{
public void run()
{
System.out.println("Printing from run():\t" + Thread.currentThread().getName());
}
}
public class ThreadImplementInterface
{
public static void main(String[] args)
{
System.out.println("Threads: Implementing Runnable Interface");
RunnableThread runnable = new RunnableThread();
Thread thread = new Thread(runnable);
System.out.println("Printing from main:\t" + Thread.currentThread().getName());
thread.start();
}
}
Output
Threads: Implementing Runnable Interface
Printing from main: main
Printing from run(): Thread-0