jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Static Constructor in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static Constructor in Java" Watch "Static Constructor in Java" New topic
Author

Static Constructor in Java

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Dear Friends,

From Thinking in Java book

in java, constructors are static implicitly

the above sentence confused me and I dont find depth discussion on this.
as far I know, you can only apply access specifier to constructor and you cant apply static.

any help?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Seetharaman Venkatasamy wrote:as far I know, you can only apply access specifier to constructor and you cant apply static.

That's what "implicit" means--it means you don't have to specify it (and as you said, you can't). The "static" is implied.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

David Newton wrote: The "static" is implied.

well David, but still you can use instance variable and *this* inside constructor which is not a static and you cant use these in static block right?.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Constructors aren't methods.

Think of it this way: An instance of a class has methods (non-static methods). A class has methods (static methods). A class has constructors (implicitly static--what would it mean for an instance to have a constructor?)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
I think it simply means the constructors belong to the class rather than to instances. But they set up instance fields.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's a clearer way of putting it, I think.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

thank you David and Campbell. I understood clearly. it is clever explanation. once again thank you
karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

Is there any specific property for a variable defined inside Static Block.Static means when the class is loaded all the static members are called only once and initialised. So whenever we create some instance variable inside static , is there any change in property for that variable.


"Learning is a Culture where your Eagerness & Curiosity plays a major Role".
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you asking if you can change the value of a property initialized inside a static initializer? Why not just try it?
karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

i have tried changing properties. But my Question is , Is there any difference in properties for an instance created inside a class normally and an instance created inside a Static initialiser. By meaning property , i here mean whether conceptually is there any difference between those, it's accessibility,Scope,etc. Thanks David.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Constructor in Java
 
Similar Threads
Inner Class
Important java interview Qs
mock exam question.can it be complied?
need of static constructor
Question about JTextComponent Heirarchy