Your code is a bit confusing. It will never compile, as that sc
instance is a DataCenter
, whereas the Singleton
class is a total different type. In fact, it is not even its subtype.
However, let me explain something in general about what you are trying to achieve.
By definition, the Singleton pattern intends to realize one single instance of a certain class for the whole program lifecycle, which you can obtain by invoking the getInstance
method.
Normally, it is the same class that you want to make Singleton that hides its contructor (by making it private) and make getInstance
method public, along with other utility methods.
If you want to use another class to make another one Singleton, I can actually recon a different design pattern. Personally, I have never seen a Singleton of singletons. Perhaps you are referring to a Factory method pattern, but I suggest that you look into its implementation carefully.
This link should answer your question: Examples of GoF Design Patterns in Java's core libraries.