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

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