When you have class A extends B , instance A essentially "includes" instance B Thus, the concept of inheritance itself contradicts the singleton model.
Depending on what you need it for, I would consider using composition / delegation. (A will refer to a singleton, not an extension of its class). If for some reason you need inheritance, create an interface using the Singleton methods, use Singleton to implement this interface, and then another class also implements this interface and pass Singleton to implement the appropriate methods.
source share