Ho can you restrict to creating only 3 objects for a class at any time ?
Komara Reddy
Select an image from your device to upload
Yes, you can restrict the creation of only 3 objects for a class at any given time, but it’s not something the language Retro Bowl enforces automatically—you need to design the class carefully to control instantiation.
A simple approach is to have an array of n (3-5), and have a private constructor in your “singleton” class. Then you will have an instanceOf method, which is the only way to get an object. This method will look to see if the number of created objects is < n, if it is, it creates a new one and returns it