Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

initializing static variable

807603Dec 13 2007 — edited Dec 14 2007
Hi everyone,

I am unclear when initializing static variables the following way:
public class Client{
 private static Resource resource = null;
 public Client(argument){
  resource = new Resource(argument);
 }
}
Let's say that multiple Client objects are instantiated. My question is what happens during the "resource" instantiation - which is part of the Client instantiation, when:
a) "argument" is always the same (i.e. a constant) across all Client instantiations, and
b) "argument" is different with every Client instantiation.

Now I believe for a) "resource" object will be unique and common for all Client instantiations,
but for b) I have doubts as to if "resource" will be unique or a new "resource" object will be created with every new Client instantiation.

Thanks much in advance for clearing this up for me.
Regards.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 11 2008
Added on Dec 13 2007
6 comments
151 views