Is it possible to apply inheritance to a Singleton class?

前端 未结 8 1974
孤独总比滥情好
孤独总比滥情好 2021-01-30 23:05

Today I faced one question in interview. Is it possible to apply inheritance concept on Singleton Classes? I said since the constructor is private, we cannot extend that Singlet

8条回答
  •  伪装坚强ぢ
    2021-01-30 23:30

    A private constructor is visible to other inner classes of that singleton class. So yes, technically a singleton class with a private constructor can be extended by its inner class. But why would you do something like that is beyond me.

提交回复
热议问题