+ 1
I wanted my class to only have one object created at any given time?
I want to limit the amount of object which can be created from a particular class , It should only have one or zero object at any give moment , I have tried a way and it seems to work Please check it out and tell me some improvements I maybe will be able to make https://code.sololearn.com/cUzUiPEKEBPL/?ref=app
1 Resposta
0
That is fine, but you can make it easier.
Just type in the constructor some int variable equal to- 0 that everytime time you create object from this class he will be raise by 1, then, put a if statement in the same constructor that if the int variable is higher then 1 you will call the distractor.