This week's giveaway is in the Cloud/Virtualization forum. We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line! See this thread for details.
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.
causes a new object of TestSam to be created. You havent overrident the default constructor to invoke go() or assign o a value. So o will still be null and hence causes the NullPointerException. HTH, Seema