PCPP1 · domain
Advanced Object Oriented Programming
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.
Focused practice
Practice Advanced Object Oriented Programming questions
Scored sessions drawing only from this domain — pick a length below.
Start 20-question practice test →What this domain covers
What to know about Advanced Object Oriented Programming
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 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__()
Why learners struggle
Why Advanced Object Oriented Programming questions are commonly missed
RAM questions are commonly missed because learners confuse physical form factors (DIMM vs SO-DIMM) and fail to distinguish between memory speed (MHz) and latency (CL).
- ·DIMM vs SO-DIMM — desktop vs laptop form factor confusion
- ·DDR3 vs DDR4 vs DDR5 — notch position and voltage differences
- ·MHz vs CL — speed vs latency trade-offs in performance
- ·Single-channel vs dual-channel — bandwidth impact misconception
- ·ECC vs non-ECC — error correction support in servers vs desktops
- ·32-bit vs 64-bit — maximum addressable RAM limit
Watch out for
Common Advanced Object Oriented Programming exam traps
- ▸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.
Question index
All Advanced Object Oriented Programming questions (68)
Click any question to see the full explanation, or start a practice session above.
A 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?
Hard2Which of the following describes the purpose of the __slots__ attribute in a class?
Easy3A 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?
Medium4You 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?
Medium5Which magic method is responsible for providing the informal string representation of an object, typically used for user-facing output?
Easy6Which magic method allows an object to behave like a function?
Medium7A 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?
Medium8In the Factory pattern, what should you do if the requested type is unknown?
Medium9You 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?
Hard10A 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?
Hard11What is the difference between a class-level variable and an instance-level variable?
Medium12You 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?
Medium13When overriding the __getattr__ method, what must you be careful to avoid?
Medium14A 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?
Medium15When using a metaclass, how can you access the class attributes during the class definition?
Medium16You 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?
Easy17Which TWO of the following are true regarding multiple inheritance in Python?
Medium18You 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`?
Hard19You 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?
Medium20What is the primary risk of using 'getattr' without a default value?
Hard21When using the __call__ method to implement a decorator, what does the decorator receive as an argument?
Medium22Why does the __init__ method not return anything?
Hard23A 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`?
Hard24What is the purpose of the 'weakref' module in relation to the Observer pattern?
Hard25How do you define a property in a class to make it read-only?
Hard26Which magic method is used to control how an instance is displayed when using the print() function?
Easy27A 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?
Medium28In the context of the Observer pattern, what is the benefit of an event-driven system over a direct-method-call approach?
Medium29What is the purpose of the __set_name__ method in descriptors?
Hard30Why should you use super() instead of calling the parent class method directly by name?
Medium31What is the purpose of the 'type' function when called with three arguments?
Medium32What does the @abstractmethod decorator do when applied to a method inside an ABC?
Medium33When 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?
Medium34What is the consequence of not calling super().__init__() in a class with multiple inheritance?
Medium35Which magic method is triggered when an object is deleted using the 'del' keyword?
Easy36What is the result of applying the @staticmethod decorator to a method inside a class that also defines a metaclass?
Hard37You 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?
Medium38What is the effect of setting __slots__ in a parent class on a child class that does not define its own __slots__?
Hard39A `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?
Easy40You 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?
Hard41Which THREE of the following are potential pitfalls of the Singleton pattern in Python?
Hard42A 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.)
Medium43How do you implement the 'Strategy' pattern in Python?
Medium44When designing a class hierarchy, what is the best way to prevent a method from being overridden by subclasses?
Medium45A 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?
Easy46You 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?
Medium47A 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`?
Hard48How do you correctly call a method from a sibling class in a diamond inheritance structure using super()?
Medium49Which TWO of the following are correct regarding the 'with' statement in Python?
Medium50In the context of the Factory pattern, what does a concrete factory implement?
Medium51When implementing the Singleton pattern, what is the advantage of using a module-level instance over a class-based Singleton?
Medium52What is the purpose of the __repr__ method?
Easy53Why does the 'abc' module provide the 'ABCMeta' metaclass?
Hard54You 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?
Hard55Which THREE of the following represent common issues when using __slots__?
Hard56You are implementing the Observer pattern. Why should you avoid using a strong reference to the observers in the subject's list?
Medium57What is the primary difference between @classmethod and @staticmethod?
Easy58Which magic method enables index access (e.g., obj[i])?
Easy59Which TWO of the following are true about magic methods?
Medium60Which TWO of the following are valid ways to create a singleton in Python?
Medium61You 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?
Medium62What happens when you add two objects of a class that implements __add__?
Easy63If you define a class with a metaclass that has a custom __call__ method, when is that __call__ method executed?
Hard64Which method is used to customize the behavior of the 'in' operator?
Easy65Which magic method should you implement to make your objects support the 'with' statement context manager?
Easy66Which function is used to check if an object is an instance of a class?
Easy67In 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?
Medium68Why might you use the __init_subclass__ hook instead of a metaclass?
HardOther domains
All PCPP1 exam domains
Frequently asked questions
- What does the Advanced Object Oriented Programming domain cover on the PCPP1 exam?
- 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.
- How many questions are in this domain?
- This page lists all 68 Advanced Object Oriented Programming questions in the PCPP1 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
- What is the best way to practise this domain?
- Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
- Can I practise only Advanced Object Oriented Programming questions?
- Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.