File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes key word static against constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "key word static against constructor" Watch "key word static against constructor" New topic

key word static against constructor

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Hi there,
Why I can not have key word static against the constructor.

Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
From the JLS 8.8.3:
Unlike methods, a constructor cannot be abstract, static, final, native, strictfp, or synchronized. A constructor is not inherited, so there is no need to declare it final and an abstract constructor could never be implemented. A constructor is always invoked with respect to an object, so it makes no sense for a constructor to be static.

If yout think about it, it makes sense. A static method is a class method is invoked without there having to be an specific object against which it is called. In other words, in an instance method there is a 'this' object that you can use to refer to the object against which the method was invoked. In a static method there is no 'this' because it is a class method not an instance method.
A constructor is more like a special case of an instance method, it has a 'this' reference in it, where 'this' refers to the object that is being created.
Hope that helps

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Thanks You Dave.
I agree. Here's the link:
subject: key word static against constructor
It's not a secret anymore!