0

Is this a correct Singleton implementation?

While preparing for a quiz, I have come accross a question about the Singleton design pattern. The code had these: - public final static instance - instance being initialized in a static block - private constructor The possible answers: a) correct Singleton implementation b) wrong Singleton implementation c) an example of lazy initialization d) an example of eager initialization e) to be a Singleton, it requires a getInstance() method f) it cannot be considered an implementation of a Design Pattern Personally I would say that b) and e) are correct, but someone else told me that the correct answers are a) and d). Can someone enlighten me? Thank you in advance!

11th Jun 2021, 10:38 AM
Ana-Maria
Ana-Maria  - avatar
1 Answer
0
this is a correct singleton implementation as you get an unique class instance (eager initialized in static block, do you doesn't need a getInstance() method)... as correct singleton implementation it can be considered as implementation of design pattern ;)
11th Jun 2021, 4:09 PM
visph
visph - avatar