Help the world stop coronavirus! Stay home!

Prev Next

Java / static keyword

What is a static variable in Java?

If you declare any variable as static, it becomes static variable or class variable.

The static variable is at class level rather than object level. If Class A has a static int variable counter and A has two instances a1 and a2 both will have a static variable counter whose value would be always same. Both instances share the same copy of static int variable.

A Static variable gets memory allocated only once during the time of class loading. A static variable can be accessed directly by calling ClassName.StaticVariableName without an instance for the class.

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

Concurrent collections

Comments & Discussions