A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Defining a thread by implementing runnable interface

thread by implementing runnable interface

Thread by implementing runnable interface

  • We can define a thread by implementing runnable interface. 

  • Runnable interface present in java.lang package and it contains only one method i.e public void run().

class MyRunnable implements Runnable
{
  public void run()
  {
  for(int i=0;i<10;i++)
  {
  System.out.println("This is child thread");
  }
  }
}
class ThreadDemoRunnable
{
  public static void main(String args[])
  {
  MyRunnable r=new MyRunnable();
  Thread t=new Thread(r);
  t.start();
  for(int i=0;i<10;i++)
  {
  System.out.println("This is main thread");
  }
  }
}

Output: we will get next output and we cannot tell exact output.



LEARN TUTORIALS

.

.