Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes need of static constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need of static constructor" Watch "need of static constructor" New topic
Author

need of static constructor

shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
why would we ever need a static constructor. what does it mean by a static constructor ?

static refers to "not associated with specific object" and can be called using class reference rather than object reference. But how does this apply to a constructor
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
sorry i got constructors are not static...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Never heard of a "static constructor". A constructor has an access modifier (public/private/protected/---) the name of the class and (parameters). You never write static.
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
shukla raghav wrote:why would we ever need a static constructor. what does it mean by a static constructor ?

static refers to "not associated with specific object" and can be called using class reference rather than object reference. But how does this apply to a constructor


The closest you come to a static constructor is a static initializer. It works like a static default constructor would work if it existed.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
It never occurred to me that could mean initialisers. Well caught, uj.
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Also discuss here


http://muhammadkhojaye.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Thank you for noticing the old thread.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: need of static constructor