So, my question is, what is the effect of making a variable static on threads?
When you created Multiple with static num and t1 and t2 as two instances of Multiple, this is what happened.
Object t1 and t2 of type Multiple shares the same memmory location for 'num'.
That means if t1 changes the value of num, the change affects num in t2 too.
if t1 changes value of num from 0 to 1, the value of num in t2 is 1 now.
if t2 changes value of num from 1 to 2, the value of num in t1 is 2 now.
and so on.
When num was not static t1 had a variable called num exclusively for t1 while t2 had a variable called num. t1.num and t2.num were two different memmory locations.
That means if t1 changes the value of num, the change doesn't affect num in t2. Intially both t1.num and t2.num were 0.
if t1 changes value of num from 0 to 1, the value of num in t2 is still 0.
if t2 changes value of num from 0 to 1, the value of num in t1 is still 1(current value of t1).
and so on.