Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

← Object-Oriented Programming practice sets

PCAP Object-Oriented Programming • Complete Question Bank

PCAP Object-Oriented Programming — All Questions With Answers

Complete PCAP Object-Oriented Programming question bank — all 0 questions with answers and detailed explanations.

138
Questions
Free
No signup
Certifications/PCAP/Practice Test/Object-Oriented Programming/All Questions
Question 1easymultiple choice
Study the full Python automation breakdown →

A developer creates a Python class with a method that is intended to be overridden in subclasses. Which approach best ensures that the method is not accidentally called on the base class?

Question 2easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer wants to ensure that a class attribute is shared among all instances but cannot be modified from outside the class. Which approach is most appropriate?

Question 3mediummultiple choice
Study the full Python automation breakdown →

A Python class 'BankAccount' has a method 'withdraw(amount)' that deducts 'amount' from 'self.balance'. A developer writes a subclass 'SavingsAccount' that overrides 'withdraw' to add a penalty if balance drops below minimum. Which design pattern is being used?

Question 4mediummultiple choice
Read the full Object-Oriented Programming explanation →

A team is developing a system that must handle different types of documents (PDF, Word, etc.). Each document type has a unique parsing method. To avoid massive conditional logic, which OOP concept should be applied?

Question 5hardmultiple choice
Read the full Object-Oriented Programming explanation →

A developer writes a class 'Logger' with a class method 'log(msg)' that writes to a file. Another class 'AppLogger' inherits from 'Logger'. The developer expects both classes to share the same file handle. However, after creating an instance of 'AppLogger', the file handle is different. What is the most likely cause?

Question 6hardmultiple choice
Read the full Object-Oriented Programming explanation →

A class 'MyClass' has a method 'do_something' that uses 'self.__private'. A subclass 'MySubClass' tries to access 'self.__private' and gets an AttributeError. Why?

Question 7hardmultiple choice
Study the full Python automation breakdown →

A Python class 'Shape' defines an abstract method 'area'. Subclasses 'Circle' and 'Square' implement 'area'. A function 'calculate_area(shape)' expects a 'Shape' instance. Which principle ensures that the function works correctly without knowing the specific subclass?

Question 8easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer defines a class 'Car' with an attribute 'wheels = 4'. They create two instances: car1 = Car() and car2 = Car(). Then they set car1.wheels = 3. What is the value of car2.wheels?

Question 9mediummultiple choice
Read the full Object-Oriented Programming explanation →

A class 'Point' is defined with __slots__ = ['x', 'y']. A developer creates an instance p = Point() and tries to set p.z = 10. What happens?

Question 10mediummultiple choice
Read the full Object-Oriented Programming explanation →

A class 'Employee' has a method 'work()'. A subclass 'Manager' overrides 'work()' but also wants to call the parent's 'work()'. Which syntax correctly achieves this?

Question 11hardmultiple choice
Read the full Object-Oriented Programming explanation →

A developer defines a class 'A' with a method 'm' that uses 'self.a'. Class 'B' inherits from 'A' and defines __init__ that sets 'self.a = 10'. An instance of B is created and method m is called. What is the output?

Question 12mediummultiple choice
Read the full Object-Oriented Programming explanation →

A developer is designing a class hierarchy for a library system. They want to ensure that a method 'borrow' in the base class 'Item' can be overridden by subclasses like 'Book' and 'DVD', but the base implementation should not be callable directly. Which approach best achieves this?

Question 13hardmultiple choice
Study the full Python automation breakdown →

A Python program uses multiple inheritance. Class A defines method 'foo', class B also defines 'foo', and class C(A, B) inherits from both. The developer expects that calling 'foo' on an instance of C should invoke the method from class A. However, it invokes the method from class B. What is the most likely cause?

Question 14easymulti select
Read the full Object-Oriented Programming explanation →

Which TWO of the following are valid ways to define a class attribute that is shared by all instances?

Question 15mediummultiple choice
Read the full Object-Oriented Programming explanation →

What is the output of the code?

Exhibit

Refer to the exhibit.

```python
class Base:
    def __init__(self):
        self._x = 10
    def get_x(self):
        return self._x

class Derived(Base):
    def __init__(self):
        self._x = 20

obj = Derived()
print(obj.get_x())
```
Question 16easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer wants to ensure that an attribute 'balance' of a BankAccount class cannot be accessed directly from outside the class but can be accessed through a method. Which approach should be used?

Question 17mediummultiple choice
Read the full Object-Oriented Programming explanation →

An engineer is debugging an application that uses inheritance. The base class 'Vehicle' defines a method 'start()' that prints 'Vehicle started'. The subclass 'Car' overrides 'start()' to print 'Car started'. The code contains a function that accepts a Vehicle object and calls 'start()'. What is the output if a Car object is passed?

Question 18hardmultiple choice
Study the full Python automation breakdown →

A Python developer is implementing a class that should behave like a sequence and support indexing. Which pair of special methods must be defined to achieve this?

Question 19easymultiple choice
Read the full Object-Oriented Programming explanation →

During code review, a team member wrote: 'class Dog(Animal): pass'. The Animal class has an __init__ method that requires a 'name' parameter. When instantiating Dog, what should be done to properly initialize the inherited attributes?

Question 20mediummultiple choice
Read the full Object-Oriented Programming explanation →

A programmer writes a class with a static method using @staticmethod. What is the primary purpose of using a static method instead of a class method or instance method?

Question 21hardmultiple choice
Study the full Python automation breakdown →

Consider the following code snippet: 'class A: pass; class B(A): pass; class C(A): pass; class D(B, C): pass'. What is the Method Resolution Order (MRO) for class D according to the C3 linearization algorithm used by Python?

Question 22mediummultiple choice
Read the full Object-Oriented Programming explanation →

A developer needs to create a class that cannot be instantiated directly but serves as a base for other classes. Which approach should be used?

Question 23easymulti select
Study the full Python automation breakdown →

Which TWO of the following are valid ways to define a class attribute (as opposed to an instance attribute) in Python?

Question 24hardmulti select
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. Which THREE statements about the class hierarchy are correct?

Exhibit

class A:
    def method(self):
        return 'A'

class B(A):
    def method(self):
        return 'B'

class C(A):
    def method(self):
        return 'C'

class D(B, C):
    pass
Question 25hardmultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class Counter:
    count = 0
    def __init__(self):
        Counter.count += 1
    @classmethod
    def get_count(cls):
        return cls.count

c1 = Counter()
c2 = Counter()
print(Counter.get_count())
print(c1.get_count())
print(c2.get_count())
Question 26mediummultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What will happen when the code is executed?

Exhibit

class MyClass:
    def __init__(self, x):
        self.__x = x
    def get_x(self):
        return self.__x

obj = MyClass(10)
print(obj.__x)
Question 27hardmultiple choice
Read the full Object-Oriented Programming explanation →

You are working on a legacy system that processes financial transactions. The system uses a class hierarchy: Transaction (base), Deposit, Withdrawal, Transfer. Each subclass overrides a method 'process()' to handle its specific logic. The code often runs in a multi-threaded environment and you notice intermittent errors where a transaction is processed twice. The logging shows that the same transaction object is being passed to the process method multiple times. The transaction objects are created from a factory function that caches recently used transactions. The errors seem to occur when two threads call the factory at the same time with the same parameters. After investigating, you find that the factory uses a class-level dictionary to cache objects. Which of the following is the most appropriate solution to prevent double processing?

Question 28mediumdrag order
Study the full Python automation breakdown →

Drag and drop the steps to define and call a function with default arguments in Python into the correct order.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 29mediumdrag order
Study the full Python automation breakdown →

Drag and drop the steps to create a Python package with subpackages into the correct order.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 30mediummatching
Study the full Python automation breakdown →

Match each Python operator to its precedence level (1=highest).

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

1

3

4

7

8

Question 31mediummatching
Read the full Object-Oriented Programming explanation →

Match each list method to its effect.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Adds x to end

Appends elements from iterable

Inserts x at index i

Removes first occurrence of x

Removes and returns last item

Question 32easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer is implementing a simple counter class. The class should start at 0 and increment by 1 each time the 'increment' method is called. Which implementation is correct?

Question 33mediummultiple choice
Study the full Python automation breakdown →

Consider the following class hierarchy: class A: def method(self): return 'A'; class B(A): pass; class C(A): def method(self): return 'C'; class D(B, C): pass. What is the output of D().method() according to Python's MRO?

Question 34hardmultiple choice
Study the full AAA explanation →

A developer wants to ensure that the 'radius' attribute of a Circle class is always non-negative. Which implementation using @property is correct?

Question 35easymultiple choice
Read the full Object-Oriented Programming explanation →

A class MyClass defines __str__ and __repr__ methods. What is the purpose of __repr__?

Question 36mediummultiple choice
Read the full Object-Oriented Programming explanation →

Consider the following code: class A: x = 1; class B(A): pass; class C(A): x = 2; class D(B, C): pass. What is D.x?

Question 37hardmultiple choice
Read the full Object-Oriented Programming explanation →

Which of the following correctly uses an abstract base class to enforce that all subclasses implement a 'make_sound' method? (Assume ABC imported)

Question 38easymultiple choice
Read the full Object-Oriented Programming explanation →

A subclass overrides a method but wants to call the parent class's version. Which keyword should be used?

Question 39mediummultiple choice
Read the full Object-Oriented Programming explanation →

Given: class A: def method(self): print('A'); class B(A): def method(self): super().method(); print('B'); class C(A): def method(self): super().method(); print('C'); class D(B, C): pass. What is printed by D().method()?

Question 40hardmultiple choice
Study the full Python automation breakdown →

Which of these is NOT a characteristic of Python's descriptor protocol?

Question 41easymulti select
Read the full Object-Oriented Programming explanation →

Which TWO statements about static methods (@staticmethod) are correct?

Question 42mediummulti select
Study the full Python automation breakdown →

Which THREE statements about inheritance in Python are correct?

Question 43hardmulti select
Study the full Python automation breakdown →

Which TWO statements about Python's name mangling are correct?

Question 44easymultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class MyClass:
    def __init__(self, value):
        self.value = value

obj = MyClass(10)
print(obj.value)
Question 45mediummultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. Which of the following correctly shows the MRO of class D?

Exhibit

class A:
    def method(self):
        return 'A'
class B(A):
    def method(self):
        return 'B'
class C(A):
    def method(self):
        return 'C'
class D(B, C):
    pass

print(D.mro())
Question 46hardmultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is printed?

Exhibit

class Cache:
    def __init__(self, func):
        self.func = func
        self.cache = {}
    def __call__(self, *args):
        if args in self.cache:
            return self.cache[args]
        result = self.func(*args)
        self.cache[args] = result
        return result

@Cache
def add(a, b):
    return a + b

print(add(1, 2))
print(add(1, 2))
Question 47easymultiple choice
Study the full Python automation breakdown →

A developer defines a class with a private attribute `_value` and wants to provide controlled access. Which approach is the most Pythonic?

Question 48easymultiple choice
Read the full Object-Oriented Programming explanation →

A parent class defines a method `move()`. A child class overrides `move()` but also needs to call the parent's version inside it. Which syntax allows that?

Question 49mediummultiple choice
Study the full Python automation breakdown →

A developer creates classes `A`, `B(A)`, `C(A)`, and `D(B, C)`. When calling a method from `D` that is defined in `A`, which class's version is used according to Python's MRO?

Question 50mediummultiple choice
Read the full Object-Oriented Programming explanation →

A class has both `@classmethod` and `@staticmethod` decorators. What is a key difference between them?

Question 51hardmultiple choice
Read the full Object-Oriented Programming explanation →

A programmer wants to restrict a class to only allow specific attribute names and reduce memory usage. Which feature should they use?

Question 52hardmultiple choice
Read the full Object-Oriented Programming explanation →

A developer implements a descriptor class with `__get__` and `__set__` methods. When an instance attribute is accessed, what determines whether the descriptor is used?

Question 53easymultiple choice
Read the full Object-Oriented Programming explanation →

A class defines a variable `count = 0`. An instance modifies `self.count = 5`. What is the value of `count` in the class namespace?

Question 54mediummultiple choice
Read the full Object-Oriented Programming explanation →

A developer is designing a system where a `Car` class needs to reuse functionality from `Engine` and `Transmission` without creating a deep hierarchy. Which OOP principle should be applied?

Question 55hardmultiple choice
Read the full Object-Oriented Programming explanation →

An abstract base class (ABC) defines an abstract method `process()`. Several subclasses implement it. A function accepts any subclass and calls `process()`. This demonstrates which OOP concept?

Question 56mediummulti select
Study the full Python automation breakdown →

Which TWO of the following statements about Python classes are true? (Select exactly 2.)

Question 57hardmulti select
Study the full Python automation breakdown →

Which THREE statements about the Python method resolution order (MRO) are true? (Select exactly 3.)

Question 58easymulti select
Study the full Python automation breakdown →

Which TWO of the following are valid ways to define a property in a Python class? (Select exactly 2.)

Question 59mediummultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output when the code is executed?

Exhibit

class MyClass:
    def __getattr__(self, name):
        return f"Default {name}"
    def __setattr__(self, name, value):
        self.__dict__[name] = value.upper()

obj = MyClass()
obj.x = "hello"
print(obj.x)
Question 60hardmultiple choice
Study the full Python automation breakdown →

Refer to the exhibit. What is the output? (Note: actual MRO may vary; choose the one that matches Python 3 C3 linearization.)

Exhibit

class A:
    def method(self):
        return "A"

class B(A):
    def method(self):
        return "B"

class C(A):
    def method(self):
        return "C"

class D(B, C):
    pass

print(D.__mro__)
Question 61easymultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class Circle:
    def __init__(self, radius):
        self._radius = radius

    @property
    def radius(self):
        return self._radius

    @radius.setter
    def radius(self, value):
        if value > 0:
            self._radius = value

c = Circle(5)
c.radius = -3
print(c.radius)
Question 62easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer wants to ensure that a class attribute is shared across all instances. Which approach should be used?

Question 63easymultiple choice
Read the full Object-Oriented Programming explanation →

A programmer writes a class with a method that should be called on the class itself, not on instances. Which decorator is appropriate?

Question 64mediummultiple choice
Study the full Python automation breakdown →

A team is using inheritance but wants to prevent a method from being overridden in subclasses. What Python feature can enforce this?

Question 65mediummultiple choice
Study the full Python automation breakdown →

A class inherits from two parent classes that both have a method with the same name. When calling the method on the child, only one parent's version is executed. What Python mechanism determines which one?

Question 66hardmultiple choice
Read the full Object-Oriented Programming explanation →

You are designing a class that should behave like a sequence and support slicing. Which special methods must be implemented?

Question 67easymultiple choice
Read the full NAT/PAT explanation →

A class has an attribute that should be computed on access and cached for subsequent accesses. Which pattern is most appropriate?

Question 68mediummultiple choice
Read the full Object-Oriented Programming explanation →

A programmer wants to create a class that cannot be instantiated directly, only through a factory method. Which approach should be used?

Question 69hardmultiple choice
Read the full Object-Oriented Programming explanation →

When a class defines both __getattr__ and __getattribute__, which one is called when accessing an attribute that exists in the instance?

Question 70easymultiple choice
Read the full Object-Oriented Programming explanation →

A class defines an __init__ method that takes optional arguments. What is the correct way to provide default values?

Question 71hardmulti select
Read the full Object-Oriented Programming explanation →

Which TWO of the following are valid ways to define a class attribute that is shared among all instances?

Question 72mediummulti select
Study the full Python automation breakdown →

Which TWO statements about inheritance in Python are true?

Question 73hardmulti select
Read the full Object-Oriented Programming explanation →

Which THREE methods must be implemented to create an immutable object that supports iteration and membership testing?

Question 74mediummultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What will be the output when the code is executed?

Exhibit

class A:
    def __init__(self):
        self.x = 1
class B(A):
    def __init__(self):
        super().__init__()
        self.x = 2
b = B()
print(b.x)
Question 75hardmultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the root cause of the error?

Exhibit

class MyClass:
    def __init__(self):
        self.name = "test"
obj = MyClass()
print(obj.age)
Question 76easymultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. Which of the following is true about MyClass?

Exhibit

>>> help(MyClass)
Help on class MyClass in module __main__:
class MyClass(builtins.object)
 |  Methods defined here:
 |  
 |  __init__(self, value)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  display(self)
 |      Print the value.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
Question 77easymultiple choice
Read the full Object-Oriented Programming explanation →

A company needs to model different types of employees. They have a base class `Employee` with a method `calculate_pay()`. For hourly employees, pay = hours * rate; for salaried employees, pay = salary. Which design approach is most appropriate?

Question 78mediummultiple choice
Read the full Object-Oriented Programming explanation →

A team is implementing a shape hierarchy with a base class `Shape` that should have an `area()` method. They want to ensure that every subclass must provide its own implementation of `area()`. Which approach should they use?

Question 79hardmultiple choice
Read the full Object-Oriented Programming explanation →

A class `ServerConfig` has a class attribute `port = 8080`. After deployment, a developer runs `ServerConfig.port = 9090` in one module, and unexpectedly all existing instances now use port 9090. What concept explains this behavior?

Question 80easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer wants to create a class that logs every attribute access on an instance. Which special method should they override?

Question 81easymultiple choice
Read the full Object-Oriented Programming explanation →

A class `Point` has an `__init__` that sets `self.x` and `self.y`. They want to compare points by equality (i.e., `p1 == p2` should work correctly). Which method should they implement?

Question 82mediummultiple choice
Read the full NAT/PAT explanation →

A programmer uses a class method to create an alternative constructor for a `Point` class. The method should parse a string like "10,20" and return a `Point` instance with x=10, y=20. Which code snippet correctly implements this?

Question 83mediummultiple choice
Read the full Object-Oriented Programming explanation →

Consider a class `D` that inherits from multiple base classes `B` and `C`. The developer wants to call a method from a specific parent class while ensuring correct method resolution order (MRO). Which is the safest way?

Question 84hardmultiple choice
Read the full Object-Oriented Programming explanation →

A class has a class attribute that is a list. A developer modifies this list via one instance, and the change is reflected in all other instances. What is the best practice to avoid this unintended sharing?

Question 85hardmultiple choice
Read the full Object-Oriented Programming explanation →

Which of the following correctly uses `__slots__` to restrict attribute creation to only `x` and `y`?

Question 86easymulti select
Study the full Python automation breakdown →

Which TWO of the following are special methods in Python?

Question 87mediummulti select
Study the full Python automation breakdown →

Which TWO of the following are true about the `__init__` method in Python?

Question 88hardmulti select
Study the full Python automation breakdown →

Which THREE of the following are true about method overriding in Python?

Question 89easymultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. Which statement correctly creates an instance of `Dog` and calls the `bark` method?

Exhibit

class Dog:
    def __init__(self, name):
        self.name = name
    def bark(self):
        return "Woof!"
Question 90mediummultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What will be the output?

Exhibit

class MyClass:
    def __init__(self):
        self.__private = 10
obj = MyClass()
print(obj.__private)
Question 91hardmultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class A:
    def method(self):
        print("A", end="")
class B(A):
    def method(self):
        print("B", end="")
        super().method()
class C(A):
    def method(self):
        print("C", end="")
        super().method()
class D(B, C):
    def method(self):
        print("D", end="")
        super().method()
obj = D()
obj.method()
Question 92easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer defines a class with an __init__ method that sets instance attributes. Which of the following is the correct way to call the parent class's __init__ from a child class?

Question 93mediummultiple choice
Read the full Object-Oriented Programming explanation →

A class named Counter has a class variable count and an instance method increment. The method is defined as def increment(self): Counter.count += 1. What will be the output after executing the following code? c1 = Counter(); c2 = Counter(); c1.increment(); c2.increment(); print(Counter.count, c1.count, c2.count)

Question 94hardmultiple choice
Study the full Python automation breakdown →

Which of the following best describes the use of the @abstractmethod decorator in Python?

Question 95easymultiple choice
Read the full Object-Oriented Programming explanation →

A programmer wants to ensure that a class attribute is the same for all instances and can be accessed via the class name. Which type of variable should be defined?

Question 96mediummultiple choice
Read the full Object-Oriented Programming explanation →

Consider the following code snippet: class A: def __str__(self): return 'A'; def __repr__(self): return 'reprA'; a = A(); print(a); print(repr(a)). What is the output?

Question 97hardmultiple choice
Read the full Object-Oriented Programming explanation →

Which of the following is a correct use of the @property decorator to create a getter and setter for an attribute named 'score' that ensures score stays between 0 and 100?

Question 98easymultiple choice
Read the full Object-Oriented Programming explanation →

A class has a method that does not access any instance or class data. What decorator should be used to define it as a utility method that can be called on the class itself without requiring an instance?

Question 99mediummultiple choice
Read the full Object-Oriented Programming explanation →

Given the following code: class Parent: def show(self): print('Parent') class Child(Parent): def show(self): print('Child') c = Child(); c.show(); super(Child, c).show(). What is the output?

Question 100hardmultiple choice
Study the full Python automation breakdown →

Which of the following is true regarding Python's method resolution order (MRO) in multiple inheritance?

Question 101easymulti select
Study the full Python automation breakdown →

Which TWO of the following statements about Python class inheritance are correct? (Select exactly two.)

Question 102mediummulti select
Study the full Python automation breakdown →

Which TWO of the following are valid ways to define a class method in Python? (Select exactly two.)

Question 103hardmulti select
Study the full Python automation breakdown →

Which THREE of the following are characteristics of Python's special methods (dunder methods)? (Select exactly three.)

Question 104mediummultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output when this code is executed?

Exhibit

class BankAccount:
    def __init__(self, owner, balance=0):
        self.owner = owner
        self.__balance = balance
    def deposit(self, amount):
        self.__balance += amount
    def withdraw(self, amount):
        if amount <= self.__balance:
            self.__balance -= amount
        else:
            print('Insufficient funds')
    def get_balance(self):
        return self.__balance

account = BankAccount('Alice', 100)
print(account.__balance)
Question 105hardmultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output and why?

Exhibit

class A:
    def __init__(self):
        self.x = 1
class B(A):
    def __init__(self):
        super().__init__()
        self.x = 2
class C(A):
    def __init__(self):
        self.x = 3
class D(B, C):
    pass

d = D()
print(d.x)
Question 106easymultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What happens when the last line is executed?

Exhibit

class MyClass:
    __slots__ = ('name', 'age')
    def __init__(self, name, age):
        self.name = name
        self.age = age

obj = MyClass('John', 30)
obj.city = 'New York'
Question 107mediummultiple choice
Read the full Object-Oriented Programming explanation →

A developer defines a class hierarchy with multiple inheritance: class A, class B(A), class C(A), class D(B,C). The method 'm' is defined only in A. What is the method resolution order for D according to the C3 linearization algorithm?

Question 108easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer wants to implement a read-only property for a class 'Temperature' that returns the temperature in Celsius but prevents external modification. Which code snippet correctly defines such a property?

Question 109hardmultiple choice
Read the full Object-Oriented Programming explanation →

A developer creates a metaclass 'Meta' that modifies class creation by adding a class attribute 'created_by' set to 'Meta'. Which code snippet correctly defines and uses this metaclass?

Question 110mediummultiple choice
Read the full Object-Oriented Programming explanation →

A developer designs a plugin system where each plugin must implement a method 'execute'. Which code snippet correctly enforces that subclasses provide an implementation using the 'abc' module?

Question 111easymultiple choice
Study the full Python automation breakdown →

A developer defines a subclass 'Dog' that overrides the '__init__' method of the parent class 'Animal'. The parent class __init__ sets a 'species' attribute. Which code ensures the parent __init__ is called correctly in Python 3?

Question 112hardmultiple choice
Read the full Object-Oriented Programming explanation →

A developer wants a class 'LoggedDict' that behaves like a dict but logs all attribute access in the console. Which method override correctly implements this for getting an attribute?

Question 113mediummultiple choice
Read the full Object-Oriented Programming explanation →

A developer defines a class 'MathUtils' with a method that performs a calculation either on the class or on instances. Which method type should be used for a method that does not depend on instance state but can be called on the class?

Question 114easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer wants a class 'Point' to have a readable string representation that returns 'Point(x, y)'. Which special method should be overridden?

Question 115hardmultiple choice
Read the full Object-Oriented Programming explanation →

A developer wants to create a custom descriptor that validates attribute values upon assignment. Which code snippet correctly implements a descriptor that ensures the assigned value is an integer?

Question 116mediummulti select
Read the full Object-Oriented Programming explanation →

Which TWO statements about the use of __slots__ in a class are correct?

Question 117hardmulti select
Study the full Python automation breakdown →

Which THREE of the following are true about Python's object-oriented programming features?

Question 118mediummulti select
Study the full Python automation breakdown →

Which TWO statements about method overriding in Python are correct?

Question 119hardmultiple choice
Study the full Python automation breakdown →

A development team is building a real-time chat application using Python. The application uses a class 'ChatRoom' that maintains a list of 'User' objects as active participants. Each User object holds a reference back to its ChatRoom to send messages. Over time, the application runs out of memory. Profiling reveals that User objects are not being garbage collected even after users disconnect. The team suspects circular references. Which solution would effectively resolve the memory leak without breaking the functionality?

Question 120mediummultiple choice
Read the full Object-Oriented Programming explanation →

A company is developing a scientific simulation framework where many different solvers must be interchangeable. The framework should enforce that each solver implements methods 'initialize' and 'step'. Developers want to use abstract base classes. Which approach should the team take to ensure that any subclass of 'Solver' cannot be instantiated unless it defines both methods?

Question 121easymultiple choice
Read the full Object-Oriented Programming explanation →

A junior developer writes a class 'Logger' that should only ever have one instance (singleton). They attempt to implement it by overriding __new__ to always return the same instance. However, when multiple threads attempt to create a Logger, they sometimes get different instances. Which modification will make the singleton thread-safe?

Question 122easymulti select
Study the full Python automation breakdown →

Which of the following statements about class inheritance in Python are true? (Choose two.)

Question 123mediummulti select
Study the full Python automation breakdown →

Which three statements about the Method Resolution Order (MRO) in Python are true? (Choose three.)

Question 124easymultiple choice
Read the full Object-Oriented Programming explanation →

A developer is building a simulation of different types of vehicles. They have a base class Vehicle with an attribute speed initialized in __init__. They also have a subclass Car that inherits from Vehicle and adds an attribute fuel_type. The developer wants to ensure that every time a Car object is created, it also initializes the speed attribute from the Vehicle class. Which approach should the developer use?

Question 125easymultiple choice
Read the full Object-Oriented Programming explanation →

A junior developer wrote a class representing a bank account with a private attribute balance. They used double underscore prefix (__balance) to make it private. However, in a test script, they are still able to access the attribute using the mangled name _Account__balance. The developer is confused about why encapsulation is not enforced. Which statement best explains this behavior?

Question 126mediummultiple choice
Read the full NAT/PAT explanation →

A team is developing a data processing pipeline where each step is a class that implements a common interface. They have defined an abstract base class DataProcessor with an abstract method process(data). Several concrete subclasses implement process. Now they need to add a new step that logs the data before processing. They want to reuse the existing processing logic without modifying the original classes. Which design pattern should they apply?

Question 127mediummultiple choice
Read the full Object-Oriented Programming explanation →

An application uses a class to represent a configuration object that reads settings from a file. The class has a class attribute config_cache that holds a dictionary of loaded configurations to avoid repeated file reads. However, the developer notices that when they modify the dictionary for one instance, it affects all instances. They want to ensure that each instance has its own copy of the configuration data upon initialization. Which change should they make?

Question 128hardmultiple choice
Read the full Object-Oriented Programming explanation →

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?

Question 129hardmultiple choice
Read the full Object-Oriented Programming explanation →

A developer is working on a class hierarchy for geometric shapes. They have a base class Shape with an abstract method area(). They also have a mixin class Drawable that provides a method draw(). They want to create a class Rectangle that inherits from both Shape and Drawable. However, they encounter a TypeError when trying to instantiate Rectangle because the abstract method area() is not implemented. Which action should they take to resolve this?

Question 130hardmultiple choice
Read the full NAT/PAT explanation →

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?

Question 131easymulti select
Study the full Python automation breakdown →

Which TWO of the following statements about class attributes in Python are true?

Question 132mediummultiple choice
Read the full Object-Oriented Programming explanation →

Given that MyClass defines __private_attr in __init__, why does this error occur?

Exhibit

Refer to the exhibit.

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    print(obj.__private_attr)
AttributeError: 'MyClass' object has no attribute '__private_attr'

Given that MyClass defines __private_attr in __init__, why does this error occur?
Question 133hardmultiple choice
Study the full Python automation breakdown →

A team is developing a banking system in Python. They have a base class Account with attributes account_number and balance, and a method __init__(self, account_number, balance) that initializes these attributes. They then create a subclass SavingsAccount that adds an attribute interest_rate. In SavingsAccount's __init__, they assign self.interest_rate = rate but do not call super().__init__. When they instantiate SavingsAccount('12345', 1000, 0.02) and attempt to print(balance), an AttributeError occurs: 'SavingsAccount' object has no attribute 'balance'. What is the most appropriate fix to ensure that the SavingsAccount includes balance and account_number without code duplication?

Question 134hardmultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class A:
    def __init__(self, val):
        self.val = val
    def __add__(self, other):
        return A(self.val + other.val + 1)
    def __str__(self):
        return str(self.val)

a = A(1)
b = A(2)
c = a + b
print(c)
Question 135hardmultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class Base:
    def __init__(self, x):
        self.x = x
    def method(self):
        return self.x * 2

class Derived(Base):
    def __init__(self, x, y):
        Base.__init__(self, x)
        self.y = y
    def method(self):
        return super().method() + self.y

obj = Derived(3, 4)
print(obj.method())
Question 136hardmultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class Counter:
    count = 0
    def __init__(self):
        Counter.count += 1
        self.id = Counter.count

c1 = Counter()
c2 = Counter()
print(c1.id, c2.id)
Question 137mediummultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class MyClass:
    def __init__(self, value):
        self.__value = value
    def get_value(self):
        return self.__value

obj = MyClass(10)
print(obj.__value)
Question 138mediummultiple choice
Read the full Object-Oriented Programming explanation →

Refer to the exhibit. What is the output?

Exhibit

class Shape:
    def area(self):
        return 0

class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius
    def area(self):
        return 3.14 * self.radius ** 2

shapes = [Shape(), Circle(2)]
for s in shapes:
    print(s.area(), end=' ')

Practice tests

Scored 10-question sessions with instant feedback and explanations.

PCAP Practice Test 1 — 10 Questions→PCAP Practice Test 2 — 10 Questions→PCAP Practice Test 3 — 10 Questions→PCAP Practice Test 4 — 10 Questions→PCAP Practice Test 5 — 10 Questions→PCAP Practice Exam 1 — 20 Questions→PCAP Practice Exam 2 — 20 Questions→PCAP Practice Exam 3 — 20 Questions→PCAP Practice Exam 4 — 20 Questions→Free PCAP Practice Test 1 — 30 Questions→Free PCAP Practice Test 2 — 30 Questions→Free PCAP Practice Test 3 — 30 Questions→PCAP Practice Questions 1 — 50 Questions→PCAP Practice Questions 2 — 50 Questions→PCAP Exam Simulation 1 — 100 Questions→

Practice by domain

Each domain maps to a weighted exam section. Focus on the domain where you are weakest.

Modules and PackagesStringsObject-Oriented ProgrammingExceptions and File I/O

Practice by scenario

Filter questions by type — troubleshooting, exhibit, drag-and-drop, PBQ, ACLs, OSPF, and more.

Browse scenarios→

Continue studying

All Object-Oriented Programming setsAll Object-Oriented Programming questionsPCAP Practice Hub