Problem statement:
Can we have private constructor in java class?
Yes ! we can have private constructor in java class.
Can we have private constructor in java class?
Yes ! we can have private constructor in java class.
- public class YesPrivateConstructor {
- private YesPrivateConstructor() {
- System.out.println("default");
- }
- public static void main(String[] args) {
- YesPrivateConstructor st = new YesPrivateConstructor();
- }
- }
Output: default
No comments:
Post a Comment