Why Both Threads Printing their own variable x value.
Punya Pratap Singh
Joined: Nov 23, 2010
In this Example when both threads are running they are printing their own values of variable x,I consider that if variable x is a global varibale for the class, then if one thread makes from x=7 to x= 8 then second thread should consider x=8,but it is considering it x=7 why ?
[NK: Added code tags. Please UseCodeTags while posting code]
new T() means a new instance of T. So you have two new instances of T, each with its own instance variable. x is an instance variable of T. It's not static. Another instance of the same class won't interfere with it.