Running multiple copies of your code implies that you are creating an entirely new process.
Its like running 2 independent processes (like 2 IEs or 2 notepads executing at once). These two processes should be totally independent.
Similarly, you are creating two different MIDlets and obviously you will have two different "counters" and hence it will always show as 1.
I believe you have misunderstood the definition of "static variables". Consider the following example.
public class abc {
static counter = 0;
abc() { // Constuctor
counter++;
}
public static void main(String[] args) {
new abc();
new abc();
new abc();
System.out.print(counter);
}
}
======
OUTPUT
======
3
==========
EXPLANATION
==========
Here, the counter is static. Moreover, it is present in thesame process. If you run two different instances of the same process, they both will have different counters. You cannot count the number of instances using "static variables"
Also, majority of the cellphones will not support executing multiple copies of the same program.
Hope I was able to explain properly
harsh2327
Junior Poster in Training
56 posts since May 2008
Reputation Points: 27
Solved Threads: 8