I get the error:
TestCounter.java:115: variable counters might not have been initialized counters[i] = new Counter(i);
You need to initialize the counters array.
Something like this:
if(success)
{
Counter[] counters=new Counters[30];
for(int i=0; i<30; i++)
{
counters[i] = new Counter(i);
System.out.println(counters[i].whatIsCounter());
}
}
By stating Counter[] counters you are not actually creating an array, you are simple declaring a reference variable counters of type Counter[].
Counter[] counters=new Counters[30] will create an array of type Counter of size 30 with each element holding null reference.
You haven't created the array, you've just declared the variable.
You need to do this:
Counter[] counters = new Counter[30];
or something similar