Saturday, April 27, 2019

Can we have private constructor in java?

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

Yes ! we can have private constructor in java class.
  1. public class YesPrivateConstructor {
  2.     private YesPrivateConstructor() {
  3.         System.out.println("default");
  4.     }
  5.     public static void main(String[] args) {
  6.         YesPrivateConstructor st = new YesPrivateConstructor();
  7.     }
  8. }
Output: default

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...