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

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...