150k views
0 votes
Urgent please!!!!!!!!!!!!!!!!!!!!!!

A program can only create one object of each class.
A. True
B. False

User DarkMatter
by
6.0k points

2 Answers

1 vote

Answer:

False.

Explanation:

User Stephen Fong
by
5.9k points
2 votes

Answer:

False / It Depends

Explanation:

The simplest way to create a class with one one instance is to use an enum. public enum Singleton { INSTANCE } You can compare this with Steve Taylor's answer to see how much simple it is than alternatives. BTW: I would only suggest you use stateless singletons. If you want stateful singletons you are better off using dependency injection. ( You can create more than one tho )

But, the singleton class means you can create only one object for the given class. You can create a singleton class by making its constructor as private, so that you can restrict the creation of the object. Provide a static method to get instance of the object, wherein you can handle the object creation inside the class only.

Hope this helps! <3

User Diralik
by
6.1k points