A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Elasticsearch in Action
this week in the
Difference between static and non-static members.
Joined: Aug 30, 2009
Sep 26, 2010 22:14:37
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."
Joined: Jul 14, 2010
Sep 26, 2010 22:23:35
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.
Attitude is everything
Joined: Aug 13, 2010
Sep 27, 2010 00:45:43
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
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
Joined: May 13, 2010
Sep 27, 2010 00:51:57
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.
Global constant in a static block
Instance vs Static Variables, Methods, Constructors? Basic understanding
static and non static
static object refrences and non static object refrences
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015