Must I add a Class Variable?
There is this concept in c++, where i can store local variable by the use of static storage class. You see this is a powerful concept where if i want to iterate through elements of a class, i simply dont have to declare an instance variable as i do in java.
I simply declare static const_iterator that will return the next element until i reach the
end of the list.
Why didnt java implement such a concept?
Re: Must I add a Class Variable?
I'm not sure what you mean by 'iterate through elements of a class', but you can declare static member variables in Java that will be shared by all instances.
So you can declare a static counter that is incremented in the constructor to track the number of instances, or a static list to which each new instance is added, so all instances are sequentially available, etc.
You only have to read a Java primer to discover this, so I'm guessing you want to do something more - can you clarify your requirement?