+ 1
What is the difference between singleton class and a normal class
please give an example
3 odpowiedzi
+ 3
A singleton class can only have one instance whereas a normal class can have many.
Ie. A normal class allows you do this:
NormalClass object1 = new NormalClass()
NormalClass object2 = new NormalClass()
For a singleton class you must do
SingletonClass.getInstance()
The get instance checks whether the object has been created and creates the object in the same way that a normal class is instantiated but this is only done once. If it has already been accessed before, it will return you the object.
+ 2
so it means if I try to create another object of singleton class then it will show error
+ 2
Yes