In java when we create a class singleton it create only one instance of that class per application, but rather than creating singleton class if we create all the methods and variables of that class static then also it will create only one instance of that static members. Then what is advantage of singleton class over all static members of class?
This is not only about java. One difference between singletons and static members is that you may have several singletons that extend or implement a same class or interface. If you need to call a method on one of these singletons, you can rely on polymorphism, which would not be the case with static members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With