Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static reference for object

 
Vijay maske
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I have object reference as static?

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the JavaRanch.
 
Bharath Raja
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Stephan van Hulst
Bartender
Pie
Posts: 5406
52
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The singleton pattern is a common example:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic