aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Author

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
Greenhorn

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: 1268

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: http://aspose.com/file-tools
 
subject: Difference between static and non-static members.
 
Similar Threads
Instance vs Static Variables, Methods, Constructors? Basic understanding
Global constant in a static block
static and non static
static object refrences and non static object refrences
JButton