This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
To be a bit more precise than "sharing a method" ... the JVM loads the bytecode for that method into memory once when the program first references the class. When you execute the method on instance 1 of the class or instance 2 of the class, the JVM steps through the very same instructions.
When you enter a method, the JVM makes new copies of the local variables, so they don't clobber each other. When you create a new instance, each instance gets its own copies of the member variables so they don't clobber each other.
This works out nicely. The JVM only loads the code once, saving some memory and time. It creates multiple copies of local and member variables to keep the object instances and threads separated. Does that make sense?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi