Card 49 / 72: Which of the following code snippet represents a Singleton design pattern implementation?
A)
public class PrintSpooler { public PrintSpooler INSTANCE = new PrintSpooler(); public PrintSpooler () {} public static PrintSpooler getInstance() { return INSTANCE; } }
B)
public class PrintSpooler { private PrintSpooler INSTANCE = new PrintSpooler(); private PrintSpooler () {} public static PrintSpooler getInstance() { return INSTANCE; } }
C)
public class PrintSpooler { private static final PrintSpooler INSTANCE = new PrintSpooler(); private PrintSpooler () {} public static PrintSpooler getInstance() { return INSTANCE; } }
D)
public class PrintSpooler { private final PrintSpooler INSTANCE = new PrintSpooler(); private PrintSpooler () {} public static PrintSpooler getInstance() { return INSTANCE; } }
Answer:
C) public class PrintSpooler { private static final PrintSpooler INSTANCE = new PrintSpooler(); private PrintSpooler () {} public static PrintSpooler getInstance() { return INSTANCE; } }
Previous Card | ← Previous Card Button |
Next Card | → Next Card Button |
Flip Card | Space-Bar |
|
Author:
JavaChamp TeamSenior Java Developer
QuizOver.com
Germany
Access: |