I am thinking about how much a class resides in memory in case it is not being accessed by other objects in memory?
for example suppose I have some class like this:
public class OrderNumber {
private static long counter = 0;
public static long getOrderNumber(){
if (counter >= 100) {
return counter = 1;
}
return ++counter;
}
}
And I call its static method from another class:
long number = OrderNumber.getOrderNumber();
each time I call it, it returns an incremental number, 1, 2, 3, 4, ...
So, My question is What is the probability of this method to return the initial value where it is supposed to return the sequenced value ??