• Source
    1. // Java Constructor as final
    2.  
    3. import java.io.*;
    4. class Example {
    5.  
    6. // Example() constructor is declared final
    7. final Example()
    8. {
    9. // This line can not be executed as compile error
    10. // will come
    11. System.out.print(
    12. "Hey you have declared constructor as final, it's error");
    13. }
    14. }
    15. class Main {
    16. public static void main(String[] args)
    17. {
    18. // Object of Example class created
    19. // Automatically Example() constructor called
    20. Example obj = new Example();
    21. }
    22. }
    23.