No Constructor can never be Final. Only private,public and protected modifiers can use with the constructor.
We use final in method level because we don't want subclass inherits that method and overwrite it . But constructor is not a method and it can not be overridden as per java specification .
Let's think in a different way
For say, constructor supports final now that mean's it can't be inherited but if you think about constructor call hierarchy then you can find the first statement of a constructor is super or this, so if the constructor is not visible how it can you call the super class constructor ? so we can't call the super class constructor, call hierarchy is uncompleted so the object will not be created. For this reason, we can't use final in the constructor.
We use final in method level because we don't want subclass inherits that method and overwrite it . But constructor is not a method and it can not be overridden as per java specification .
Let's think in a different way
For say, constructor supports final now that mean's it can't be inherited but if you think about constructor call hierarchy then you can find the first statement of a constructor is super or this, so if the constructor is not visible how it can you call the super class constructor ? so we can't call the super class constructor, call hierarchy is uncompleted so the object will not be created. For this reason, we can't use final in the constructor.
Post a Comment