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

Recommended Answers

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.