This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between static and non-static members.

 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difference between static and non-static members. Please do not explain it theoretically
 
subhash kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
eric totte
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup all static members are class members....

while non static are as the instance created per class

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic