Hi Sudha,
Following is my View regarding your doubt:
Let us analyse following four lines of code.
public static void main(String arg[]) {
// Following two lines, u are creating thread
Tes1 t1 = new Tes1("One");
Tes1 t2 = new Tes1("Two");
// When executing the following line, the "One" is printed
System.out.println(t1.getName());
// When executing the following line, your thread t1 first makes its entry with Thread Schedular and then state called "Eligible for run". And now your thread is competing for CPU time to execute. It does not mean that the moment you execute t1.start(), your thread has to execute. Before your thread get the time to execute, current thread (ie main method, it is also thread, goes to next lines of code to execute. Hence your output comes like this. It is dependent on CPU and how it schedules the thread.
t1.start();
System.out.println(t2.getName());
t2.start();
}
I hope this solves, your doubt. If i am wrong, please correct me.
You can mail me to
sakthima@rediffmail.com Thanks
Sakthivel.