How to Create a Thread using Runnable Interface in Core Java

In this tutorial how to create a Thread using Runnable Interface in Core Java is shown.

Code:

Thread2.java

class MyThread implements Runnable
{
public void run()
{
try
{
for(int i=0;i<10;i++)
{
Thread.sleep(2000);
System.out.print(” “+String.valueOf(i));
}
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
}

class RunnableDemo
{
public static void main(String args[])
{
MyThread R1 = new MyThread();
Thread t1 = new Thread(R1);
t1.start();
}
}

Add a Comment

Your email address will not be published. Required fields are marked *