static variables ' like in C ' java

T

Thomas

The C language alows to use the static keyword :
(.. )'static' can also be defined within a function. If this is done, the
variable is initalised at compilation time and retains its value between
calls.
Is there any equivalent of this feature in java ?
 
E

Eric Sosman

Thomas said:
The C language alows to use the static keyword :
(.. )'static' can also be defined within a function. If this is done, the
variable is initalised at compilation time and retains its value between
calls.
Is there any equivalent of this feature in java ?

No exact equivalent. A reasonably close approximation
is a class variable:

class Thing {

// initialized when Thing class is loaded,
// retains last-stored value until program
// exits or class is unloaded, whichever
// comes first:
static Whatever what;

...
}
 
R

Roedy Green

The C language alows to use the static keyword :
(.. )'static' can also be defined within a function. If this is done, the
variable is initalised at compilation time and retains its value between
calls.
Is there any equivalent of this feature in java ?

See http://mindprod.com/jgloss/static.html

Java has static variables and methods, just like C++. However, it
does not have local static variables. You have to use class statics
instead and use a naming convention that suggests they are intended to
be used by only a single method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top