Is it possible to apply inheritance to a Singleton class?

Posted by Bragaadeesh on Stack Overflow See other posts from Stack Overflow or by Bragaadeesh
Published on 2010-05-05T12:04:22Z Indexed on 2010/05/05 12:08 UTC
Read the original article Hit count: 212

Hi,

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 Singleton class (can someone please validate this).

Next thing he asked me is to apply inheritance on that Singleton class. So, I made the Singleton's constructor as protected thinking that child's constructor also has be protected. But I was wrong the child can have a modifier either equal to or higher than that.

So, I asked him to give a real world example on such a case. He was not able to give me one and said that I cant ask questions and wanted me to tell whether this scenario is possible or not.

I went kind of blank. My question here is,

Is this possible?

Even if its possible, what is the use of it?

What real world scenario would demand such a use.

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about singleton