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

Can we declare a constructor as private?

Isabella Wilson | 2023-05-05 12:30:29 | page views:1755
I'll answer
Earn 20 gold coins for an accepted answer.20 Earn 20 gold coins for an accepted answer.
40more

Olivia Davis

Studied at Princeton University, Lives in Princeton, NJ
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-05 12:30:29

Lucas Brown

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