QuesHub > 函数 > 静态 > 方法 > ASK DETAIL

Can we have private constructor in Java?

Charlotte Roberts | 2023-05-05 12:30:36 | page views:1780
I'll answer
Earn 20 gold coins for an accepted answer.20 Earn 20 gold coins for an accepted answer.
40more

Charlotte Anderson

Studied at the University of Zurich, Lives in Zurich, Switzerland.
Some reasons where you may need private constructor: The constructor can only be accessed from static factory method inside the class itself. Singleton can also belong to this category. A utility class, that only contains static methods. Yes, class can have a private constructor.
2023-05-07 12:30:36

Noah Lee

QuesHub.com delivers expert answers and knowledge to you.
Some reasons where you may need private constructor: The constructor can only be accessed from static factory method inside the class itself. Singleton can also belong to this category. A utility class, that only contains static methods. Yes, class can have a private constructor.
ask:3,asku:1,askr:137,askz:21,askd:152,RedisW:0askR:3,askD:0 mz:hit,askU:0,askT:0askA:4