/**
* Demo how threads in Java work
***/
public class ThreadDemo
extends Thread
{
private int startingNumber=0;
public ThreadDemo(int startingNumber)
{
this.startingNumber=startingNumber;
}
// this method runs in a separate thread
public void run()
{
//loop 10 times
for (int i=startingNumber; i < (startingNumber+100); i++)
System.out.println(i);
}
// test driver
public static void main(String args[]) throws Exception
{
ThreadDemo t1=new ThreadDemo(100),
t2=new ThreadDemo(200);
t1.start();
t2.start();
}
}