This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Static reference for object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static reference for object" Watch "Static reference for object" New topic
Author

Static reference for object

Vijay maske
Greenhorn

Joined: Oct 29, 2010
Posts: 2
Can I have object reference as static?

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Yes you can.

Please UseCodeTags when posting code. It will highlight your code and make it much easier to read. It probably will also increase the number of people helping you. I'll add them for you since you are new so that you can see the difference.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

And welcome to the JavaRanch.
Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
Wouter Oet wrote:
Yes you can.


I'm agree with you... But the main behavior of static modifier is available before we instantiate the class, right... then what is the purpose of having reference variable as static...


Life is either daring something or nothing - Helen Keller
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3573
    
  14

The singleton pattern is a common example:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Static reference for object
 
Similar Threads
Calling already instantiated objects
what exactly is -Toplevel class
Single tone Vs Static
Why can't I inherit an interface of a Class in Java
Passing variables