+ 1
Why java doesn't support static constructor , it's true for c#?
4 ответов
+ 5
In Java simply use a static block or better: use a static factory method, that calls a private constructor, see Effective Java by Joshua Bloch ;)
+ 4
static method cannot be inherited in the sub class because they belong to the class in which they have been declared.
since each constructor is being called by its subclass during creation of the object of its subclass, so if you mark constructor as static the subclass will not be able to access the constructor of its parent class because it is marked static and thus belong to the class only. This will violate the whole purpose of inheritance concept and that is reason why a constructor cannot be static.
+ 2
A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced.
We have no control on when the static constructor is executed in the program.
+ 1
If we define static constructor in c# then?