For example, consider the following toy problem:
public class Counter {
int i = 0;
public void count() {
int limit = i + 100;
while (i++ != limit) System.out.println(i);
}
}
public class CounterThread extends Thread {
Counter c;
public static void main(String[] args) {
Counter c = new Counter();
CounterThread ct1 = new CounterThread(c);
CounterThread ct2 = new CounterThread(c);
ct1.start();
ct2.start();
}
public CounterThread(Counter c) {
this.c = c;
}
public void run() {
c.count();
}
}
Given these two classes what do you expect the output will be?If you're reading this on the web before class, I really want you to think about this problem before moving on to the next page. Give it some real thought; then run the program and see if that is indeed what happens.