PCAP Object-Oriented Programming • Set 3
PCAP Object-Oriented Programming Practice Test 3 — 15 questions with explanations. Free, no signup.
A developer is implementing a caching system where object instances should be reused if they have the same set of initialization parameters. They want to control object creation so that calling MyClass(param1, param2) returns the same instance if it has been created before, otherwise creates a new one. They are considering overriding __new__ to implement this caching. However, they also need to ensure that __init__ is not called again for cached instances. What is the correct way to achieve this?
Choose an answer to begin — your selection is scored in the full session.
15 questions · instant feedback and full explanations after every question.