Saturday, April 27, 2019

Can we have final constructor in java class?

Problem statement:
Can we have final constructor in java class?

No ! we cannot have final constructor in java class.
  1. public class NoFinalConstructor {
  2.     public final NoFinalConstructor() {
  3.         System.out.println("default");
  4.     }
  5.     public static void main(String[] args) {
  6.         NoFinalConstructor st = new NoFinalConstructor();
  7.     }
  8. }
Output: compile time error - modifier 'final' is not allowed.

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...