This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Difference between static and non-static members. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between static and non-static members." Watch "Difference between static and non-static members." New topic

Difference between static and non-static members.

Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
Difference between static and non-static members. Please do not explain it theoretically

Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
subhash kumar
Ranch Hand

Joined: Jul 14, 2010
Posts: 63
If you want to count the number of objects(boxes) created of Box class then static variable will be needed.
If color property of Box class needed then we can make color as non static as it will be in every object of Box class.

Subhash Kumar
Attitude is everything
eric totte

Joined: Aug 13, 2010
Posts: 10
Static would mean there is only one instance of the member throughout ALL instantiations of the class.

Therefore within a class named "Car":

static int wheels = 4;

No matter how many Car objects you create, there will be only one wheels instance.

If you wanted each car object to have its own name, you would make

String name = "Mazda"

a non-static variable. Each new Car object will have its own name.

Theory: static is one per class, non-static is one per object of that class.
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1281

yup all static members are class members....

while non static are as the instance created per class

No Kaustubh No Fun, Know Kaustubh Know Fun..
I agree. Here's the link:
subject: Difference between static and non-static members.
jQuery in Action, 3rd edition