The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

static variables in java

Posted by mark on November 04, 2000 at 7:27 PM

> What do you want to achieve declaring a varialbe as static within a method?


in C functions, static variables let you count each time the function is called. for example, the following code would print out 1 2 3. Java doesnt let you do this because main() is a member function and they want you to make all static variables members of the program class. (C has more power here than java)

static int statFunc(){
static int i=0;
i++;
cout<<"i ";
}
void main(){
statFunc();
statFunc();
statFunc();
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us