Private constructor in abstract class

后端 未结 7 1141
无人及你
无人及你 2020-12-31 05:54

In Java what is the purpose of using private constructor in an abstract class?

In a review I got this question, and I am curious, for what situation we need to use

7条回答
  •  再見小時候
    2020-12-31 06:40

    1. As mentioned, to be used as a common, internal-use only constructor.

    2. Abstract or not abstract, it's not uncommon to declare a private default constructor on a class containing only static public methods [helper methods] to prevent instantiating the class.

提交回复
热议问题