When we go for Static member and Nonstatic member in java?

Recommended Answers

static = one value, shared for all instances of the class
non-static = every instance has its own values

Jump to Post

All 2 Replies

static = one value, shared for all instances of the class
non-static = every instance has its own values

static is the equivalent of a global variable in Java.
You usually want to avoid it, as it violates object oriented principles.

Mostly you'll see it used for constants, and sometimes utility functions that effectively exist outside of the context of any class instance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.