+ 1

Why constructors cannot be abstract or static or final?

3rd Jan 2019, 8:29 AM
Nitin Gutte
Nitin Gutte - avatar
2 Réponses
+ 5
A constructor is not a method but its a code that initialize an object state. - Why ctors cannot be abstract? Like said a ctor is not a method and is not inheritable. Abstract is used on inheritable things like classes and methods then it dont make sense on ctors - And static ctor? Like i said, a ctor is a special code that init an object state in object context while static names (attrs, methods etc) are executed at class context. This make nosense declare a ctor static because its like declare a ctor for init a not-object. For make initialization at class level you can use a static initializator block - And final? Similar motivations of abstract. Final is used for dont allow redefinition (eg. inherited class cannot redefine the name) but because a ctor is not inheritable, the final statement dont make sense
3rd Jan 2019, 8:59 AM
KrOW
KrOW - avatar
+ 2
I mean why would they be? Where would you use it? abstract constructor as well as static constructor are oxymorons imo. And when you want "final constructor" you just put this keyword in front of class definition...
3rd Jan 2019, 9:02 AM
Jakub Stasiak
Jakub Stasiak - avatar