PCAP • Hard Questions
The 25 most difficult PCAP questions — topics that eliminate candidates. Full explanations for every option.
An application uses a heavy-weight class DatabaseConnection that establishes a network connection upon instantiation. The class is used in multiple places, and the developer wants to ensure that only one instance of DatabaseConnection exists throughout the application. They implement a Singleton pattern using a class attribute _instance and a class method get_instance(). However, they notice that the network connection is being established multiple times. After debugging, they find that the singleton is not being enforced because the __init__ method is called every time the class is instantiated, even if the same instance is returned. They want to fix this so that the connection is established only once. Which modification should they make?
Choose an answer to begin — your selection is scored in the full session.
25 questions · instant feedback and full explanations after every question.