Is there a way to use internal static variables in Java? e.g take this C code:
void increment(){
static int i = 0;
i++;
printf("%i",i);
}
How would I do this in Java?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Java doesn’t have any direct equivalent – all state which you want to be persisted across method calls has to be stored in fields rather than local variables. So you can have this:
… but of course the other methods in the same class have access to
counteras well.