Doraemon,
Its because when you call start() of a
thread, its run() gets called in a new call stack. In your code, the new stack gets created in this line:
new Thread(new TestSam()).start(); In the new call stack thus created, the object "o" that you had created in main's call stack is not visible and hence you get NullPointerException in your run() method when you call a method with that invisible object.
Try including this line just before the line calling start() in run method.
Test o = new Test (); You will not get an exception.