Menu
Topics Index
...
`

Simple Thread Program - Java Example Program


Simple Thread Program
class SimpleThread extends Thread
{
    public static void main(String[] args)
    {
        SimpleThread st = new SimpleThread(); // LINE A
        st.start(); // LINE B
    }
    
    public void run()
    {
        System.out.println("Thread running...");
    }
    

}
OUTPUT

Thread running...

DESCRIPTION

In the above program our class SimpleThread extends Thread so we can create Threads for our class as like we have done at LINE A. At LINE B we started the thread using Thread's start method which internally calls Thread's run method. Since we created a thread for SimpleThread it's run method is called.

THINGS TO TRY
  • Create one more thread for SimpleThread
    Thread t2 = new SimpleThread();
    t2.start();

© meritcampus 2019

All Rights Reserved.

Open In App