Consider we have something like this:
public class Test { public static void main(String[] args) throws InterruptedException { Example b = new Example(); b.start(); } } class Example extends Thread { int total,count; @Override public void run(){ for(int i =0;i<5;i++){ total+=i; System.out.println(i+" "+total); } } }
The result is:
0 0
1 1
2 3
3 6
4 10
How to understand these results? Iteration is only 4, but class field 'total' is 10. How?