W. Joe Smith wrote:What would be the point of a static constructor? Why would you want to run a constructor, usually used to set the initial value of instance variables, without an instance of a class?
A constructor is called before an instance is created. Therefore you could say it is always static. In fact, in Delphi, you create objects by calling the constructor as if it were a static method:
The reason you can't add these keywords is probably simple: why would you need them? Would it make a difference is you added them? No it wouldn't. So to avoid confusion, they are simply forbidden.
If you ask me would it make a difference ? I would say yes it makes a difference. In java anything that can't be inherited/overridden is made final. Then in that case since constructor cannot be overridden why not make them final ???
However final modifier cannot be applied to Java. I would like to get some better explaination for this . Thanks in advance.
Note that a constructor is not a method - it's a special block of code that's executed to initialize a new instance of a class. So the rules that apply to normal methods are not necessarily applicable to constructors.
As the others have already said, modifiers such as static and final simply have no meaning for constructors, and it doesn't make sense to use those modifiers on constructors. If it would be allowed to use those modifiers, it would only be confusing - then people would be asking themselves why you can use those modifiers, while they don't mean anything.
Why do you insist on having the possibility of using static and final on constructors when you already know it wouldn't be useful? What would be the difference between a constructor that is static or final and a constructor that is not static or final?