Is it possible to apply inheritance to a Singleton class?

前端 未结 8 1984
孤独总比滥情好
孤独总比滥情好 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:43

    Its 'possible' to hack anything together really, but in this case it is not really advisable. There's no real reason to use the singleton pattern with inheritance, its just not meant for it.

提交回复
热议问题