File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static reference for object" Watch "Static reference for object" New topic

Static reference for object

Vijay maske

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

Joined: Sep 20, 2010
Posts: 4624

The singleton pattern is a common example:

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
I agree. Here's the link:
subject: Static reference for object
It's not a secret anymore!