can we make a constructor final in java?

No, we cannot make constructor as final in java.

For methods, final keyword is used to prevent them to be overridden by subclass. Constructors are also the special kind of methods but as we know that constructor can not be inherited in subclass, hence there is no use of final keyword with constructor.

If we declare constructor as final, compiler will give compile time error. Please see the below example:

public class Main
    final Main(){
        System.out.println("Final Constructor");
	public static final void main(String[] args) {
	    Main obj1 = new Main();

Output error: modifier final not allowed here
    final Main(){
1 error

Java interview questions on constructor

Please follow and like us:
Content Protection by
togel situs toto situs togel situs toto situs toto agen togel situs togel situs togel togel situs togel resmi situs togel situs togel situs toto link togel togel online