You must read Python class code and predict runtime behavior: method binding, MRO, __slots__ effects, and pattern roles. The single most important thing is knowing exactly what each construct does at runtime, especially classmethod binding and cooperative super() calls in multiple inheritance.
Start practicing
Advanced Object Oriented Programming — choose a session length
Free · No account required
Domain overview
This domain of the PCPP1 exam covers Python's advanced object-oriented machinery: design patterns such as Factory and Singleton, class and static methods, metaclasses, multiple inheritance and MRO, abstract base classes, and memory/attribute control through __slots__. Questions are code-reading and behavior-prediction items: you must reason about what Python actually does at runtime, not just name a concept.
Exam objectives
The Factory pattern: what a concrete factory implements versus an abstract factory interface
@classmethod versus @staticmethod: binding to the class, first argument, and inheritance behavior
__slots__ inheritance: whether a child without its own __slots__ still gets a __dict__
Multiple inheritance: MRO resolution and the consequence of skipping super().__init__()
Assuming a child class inherits the parent's __slots__ restriction; a child without __slots__ regains a __dict__ and allows new attributes.
Confusing @classmethod with @staticmethod: only the classmethod receives the class as its implicit first argument and follows inheritance.
Forgetting that omitting super().__init__() in a cooperative multiple-inheritance chain leaves later base classes uninitialized, causing missing attributes.
Click any question to see the full explanation and answer options, or start a focused practice session above.
How do you correctly call a method from a sibling class in a diamond inheritance structure using super()?
2Which magic method is responsible for providing the informal string representation of an object, typically used for user-facing output?
3What is the result of applying the @staticmethod decorator to a method inside a class that also defines a metaclass?
4You are implementing the Observer pattern. Why should you avoid using a strong reference to the observers in the subject's list?
5When using abstract base classes (ABCs) from the abc module, what happens if a class inherits from an ABC but fails to implement one of the abstract methods?
6Which magic method should you implement to make your objects support the 'with' statement context manager?
7Which of the following describes the purpose of the __slots__ attribute in a class?
8In the context of the Factory pattern in Python, what is a typical benefit of using a registry-based approach instead of a large if-else block?
9When overriding the __getattr__ method, what must you be careful to avoid?
10Which magic method allows an object to behave like a function?
11What is the effect of setting __slots__ in a parent class on a child class that does not define its own __slots__?
12If you define a class with a metaclass that has a custom __call__ method, when is that __call__ method executed?
13When implementing the Singleton pattern, what is the advantage of using a module-level instance over a class-based Singleton?
14Which magic method is used to control how an instance is displayed when using the print() function?
15Why might you use the __init_subclass__ hook instead of a metaclass?
16When designing a class hierarchy, what is the best way to prevent a method from being overridden by subclasses?
17In the context of the Observer pattern, what is the benefit of an event-driven system over a direct-method-call approach?
18What is the primary difference between @classmethod and @staticmethod?
19Why does the 'abc' module provide the 'ABCMeta' metaclass?
20In the Factory pattern, what should you do if the requested type is unknown?
21What is the purpose of the 'weakref' module in relation to the Observer pattern?
22Which method is used to customize the behavior of the 'in' operator?
23How do you define a property in a class to make it read-only?
24What does the @abstractmethod decorator do when applied to a method inside an ABC?
25What is the consequence of not calling super().__init__() in a class with multiple inheritance?
26Which magic method enables index access (e.g., obj[i])?
27How do you implement the 'Strategy' pattern in Python?
28What is the difference between a class-level variable and an instance-level variable?
29What is the purpose of the 'type' function when called with three arguments?
30Which magic method is triggered when an object is deleted using the 'del' keyword?
31Which TWO of the following are valid ways to create a singleton in Python?
32Which TWO of the following are true regarding multiple inheritance in Python?
33Which TWO of the following are correct regarding the 'with' statement in Python?
34Which TWO of the following are true about magic methods?
35What is the purpose of the __repr__ method?
36When using the __call__ method to implement a decorator, what does the decorator receive as an argument?
37Which THREE of the following are potential pitfalls of the Singleton pattern in Python?
38In the context of the Factory pattern, what does a concrete factory implement?
39What is the primary risk of using 'getattr' without a default value?
40Which function is used to check if an object is an instance of a class?
41Which THREE of the following represent common issues when using __slots__?
42Why should you use super() instead of calling the parent class method directly by name?
43What happens when you add two objects of a class that implements __add__?
44Why does the __init__ method not return anything?
45What is the purpose of the __set_name__ method in descriptors?
46When using a metaclass, how can you access the class attributes during the class definition?
47You are designing a plugin system where each plugin class must automatically register itself with a central registry when defined, without requiring an explicit decorator or registration call. You decide to use the __init_subclass__ hook in the base Plugin class. Which statement correctly describes how to implement this so that every subclass is registered with its own class object?
48You are designing a class `Matrix` that supports element-wise addition and scalar multiplication. You want `m1 + m2` to return a new `Matrix` without modifying `m1` or `m2`. You have implemented `__add__` correctly. A colleague writes `m1 += m2` and expects `m1` to be rebound to a new `Matrix` object. However, after the statement, `m1` still refers to the same object and its internal data has been modified in place. Which change to your class is the most likely cause of this behavior?
49You are implementing a class that represents a monetary amount. You want the expression amount1 + amount2 to return a new Money instance, and you also want amount1 + 5 to work by treating 5 as a Money with zero cents. However, 5 + amount1 should raise a TypeError. Which implementation achieves this behavior?
50A developer creates a class named `Registry` in a module. The class inherits from `ABCMeta` and defines a `__new__` method that performs validation on the class namespace before the class is created. Inside `__new__`, the developer needs to inspect the attributes defined in the class body of the class being created. Which parameter of `__new__` provides direct access to those attributes?
51You are designing a class `Connection` that must ensure only one instance exists and that the same instance is returned whenever `Connection()` is called. You implement this using `__new__` to control instance creation, and you also define `__init__`. During testing, you notice that `__init__` runs every time `Connection()` is called, even though `__new__` returns the existing singleton instance. What is the most appropriate way to prevent `__init__` from reinitializing the singleton on subsequent calls?
52You are creating a class where you want to prevent instances from having a __dict__ to save memory. You add __slots__ = ('x', 'y') to the class. Which statement is true about this class?
53You are designing a class hierarchy for a document processing system. The base class `Document` defines a method `render()` that returns a string. You want subclasses to be forced to provide their own implementation, and you want to prevent `Document` from being instantiated directly. Which code correctly enforces this requirement?
54A developer defines a class `Temperature` that stores a Celsius value in `self._celsius` and exposes a `celsius` property with a setter that validates the value is not below absolute zero. After instantiating `t = Temperature(20)`, the developer runs `t.celsius = -300`. What happens?
55You are implementing a class `Vector` that supports addition and scalar multiplication. You want `v1 + v2` to return a new `Vector`, and `v1 * 3` to return a new scaled `Vector`. You also want `3 * v1` to work identically. Which pair of methods must you implement to support both `v1 * 3` and `3 * v1` correctly, assuming `v1` is a `Vector` and `3` is an `int`?
56A developer wants to ensure that a method `area` in a base class `Shape` must be overridden by any concrete subclass. The developer writes `class Shape(ABC):` and `@abstractmethod def area(self): ...`. A colleague then creates `class Circle(Shape):` without implementing `area` and tries to instantiate `Circle()`. What happens?
57A library defines a base class `Plugin` with `__init_subclass__(cls, **kwargs)` that automatically registers every subclass in a global registry using `cls.__name__`. A developer writes `class MyPlugin(Plugin, priority=5): pass` but the registration fails with a TypeError about unexpected keyword arguments. What is the most likely cause?
58A developer defines `class Config:` with `__slots__ = ('host', 'port')`. Later, they want to add a new attribute `timeout` to an existing instance without modifying the class. They write `cfg.timeout = 30` and receive an `AttributeError`. Which change would allow per-instance `timeout` assignment while keeping `__slots__` for `host` and `port`?
59A developer writes a class `Money` that implements `__eq__` to compare amounts and currencies, but does not implement `__hash__`. Instances of `Money` are then used as keys in a `set`. What is the result?
60You are designing a plugin registry that must automatically register every concrete subclass of a base class `Plugin` at the moment the subclass is defined, without requiring any explicit registration call in the subclass body. You want to avoid a metaclass because the project already uses `ABCMeta` for the base class and you do not want to introduce metaclass conflicts. Which approach best satisfies this requirement?
61A developer is implementing the Observer pattern and wants to store a list of observers without preventing them from being garbage collected when no other references exist. They decide to use `weakref.WeakSet` to hold the observers. Which statement accurately describes the behavior they should expect?
62A developer implements a class `Vector` with `__add__` returning a new `Vector`, and also defines `__iadd__` that mutates `self` in place and returns `self`. A colleague writes `a = Vector(1,2); b = Vector(3,4); c = a; a += b`. What is the state of `c`?
63You are implementing a class `Matrix` that supports the `+` operator for matrix addition. You want `m1 + m2` to return a new `Matrix`, and you also want `sum([m1, m2, m3])` to work correctly. You define `__add__` to return a new `Matrix`. However, `sum([m1, m2, m3])` raises a `TypeError`. What is the most likely reason?
64A teammate writes a `Money` value object that defines `__eq__` to compare amounts and currencies, and `__hash__` to hash the same two fields. During a code review you notice that a subclass `Discount` adds a `percentage` field, overrides only `__eq__` to include that field, and leaves `__hash__` inherited. Objects of `Discount` are then used as dictionary keys. What is the actual runtime consequence?
65A developer is designing a `Shape` base class and wants subclasses to be forced to implement an `area()` method. Which two approaches are valid in Python for enforcing that subclasses provide `area()`? (Choose two.)
66You are implementing a `Vector` class whose instances should support `v1 + v2` and also `v1 + 5`, where the second form broadcasts the scalar across every component. A colleague suggests relying on `__radd__` to handle the scalar case. Why is that insufficient?
67You are writing a class `Temperature` that should support addition and comparison. You want `t1 + t2` to return a new `Temperature` object, and `t1 == t2` to compare their values. Which magic methods must you implement to achieve this?
68A `Temperature` class stores a numeric `celsius` attribute. Callers keep assigning `temp.celsius = -500`, which is physically impossible. You want any assignment below absolute zero to raise `ValueError` while keeping normal attribute access unchanged. Which construct should you implement?
You must read Python class code and predict runtime behavior: method binding, MRO, __slots__ effects, and pattern roles. The single most important thing is knowing exactly what each construct does at runtime, especially classmethod binding and cooperative super() calls in multiple inheritance.
The Courseiva PCPP1 question bank contains 68 questions in the Advanced Object Oriented Programming domain. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Advanced Object Oriented Programming domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included