Object-Oriented Programming (OOP) in Python is a programming paradigm that uses classes and objects to model real world entities, promoting code reusability, modularity, and organization. Core principles include inheritance, polymorphism, encapsulation, and abstraction, which allow developers to build scalable applications. Python supports these concepts seamlessly through built-in syntax structures, constructor methods like init, and special magic methods. These practice MCQs are designed to test and reinforce your grasp of Python’s object-oriented principles for exams and technical interviews.
Python OOP MCQs
1 min read
Correct Answer: b) Inheritance
Explanation:
Inheritance allows a derived class to inherit attributes and methods from a base class, promoting code reusability.
Correct Answer: a) self
Explanation:
By convention, 'self' is used as the first parameter name in instance methods to refer to the instance invoking the method.
Correct Answer: b) @classmethod
Explanation:
The @classmethod decorator binds the method to the class rather than its instance, passing the class itself as the first argument (cls).
Correct Answer: b) Using double leading underscores (__attr)
Explanation:
Double leading underscores trigger name mangling in Python, prefixing the attribute name with '_ClassName'.
Correct Answer: b) __del__
Explanation:
The __del__ method is known as the destructor and is called when an instance is about to be destroyed.
Correct Answer: b) super()
Explanation:
The super() function returns a proxy object that allows you to call methods of the parent or sibling classes.
Correct Answer: a) @property
Explanation:
The @property decorator allows methods to be accessed like attributes, executing getter logic behind the scenes.
Correct Answer: b) A class inheriting from more than one base class
Explanation:
Multiple inheritance occurs when a derived class inherits features from multiple parent classes.
Correct Answer: b) Method Resolution Order (MRO) using C3 Linearization
Explanation:
Python computes an MRO using the C3 linearization algorithm to ensure monotonic and consistent method resolution.
Correct Answer: b) __mro__
Explanation:
The __mro__ tuple attribute provides the method resolution order for a given class.
Correct Answer: a) abc
Explanation:
The 'abc' module provides infrastructure for defining Abstract Base Classes in Python.
Correct Answer: b) @abstractmethod
Explanation:
The @abstractmethod decorator marks methods as abstract, requiring subclasses to implement them.
Correct Answer: b) No, it raises a TypeError if it has abstract methods
Explanation:
Instantiation of an ABC fails with a TypeError if any abstract methods remain unimplemented in the class or its subclasses.
Correct Answer: b) A programming style where an object's suitability is determined by the presence of methods and properties rather than explicit inheritance
Explanation:
Duck typing focuses on what an object can do ('If it walks like a duck and quacks like a duck...') rather than its class hierarchy.
Correct Answer: a) __add__
Explanation:
The __add__ special method implements behavior for the binary addition operator (+).
Correct Answer: b) Giving standard operators custom meanings for user-defined classes
Explanation:
Operator overloading lets classes define custom implementations for built-in operators like +, -, and *.
Correct Answer: c) __len__
Explanation:
The len() function invokes the __len__ special method on the target object.
Correct Answer: b) The method receives neither 'self' nor 'cls', acting like a regular function housed inside a class namespace
Explanation:
Static methods do not receive any implicit first arguments and behave like normal functions grouped inside a class for logical scoping.
Correct Answer: a) issubclass()
Explanation:
The issubclass(class, classinfo) built-in function checks if a class is a subclass of another.
Correct Answer: b) It prints a default string containing the object's memory address and class name
Explanation:
Without __str__ or __repr__, Python falls back to object's default representation showing the class name and hexadecimal memory address.
Correct Answer: a) __format__
Explanation:
The __format__ special method customizes how an object is formatted inside f-strings or str.format().
Correct Answer: b) obj.score = 10
Explanation:
Assigning a value to a property attribute automatically triggers its defined setter function.
Correct Answer: a) Building complex classes by combining objects of other classes as components
Explanation:
Composition models a 'has-a' relationship where a class contains instances of other classes as member variables.
Correct Answer: b) Using a unified interface for different underlying data types or classes
Explanation:
Polymorphism allows different types of objects to be handled through the same uniform interface.
Correct Answer: b) __call__
Explanation:
Implementing the __call__ method allows instances of a class to be invoked directly using parentheses like a function.
Correct Answer: a) To create classes, acting as a 'class of a class'
Explanation:
A metaclass defines how classes themselves are constructed, intercepting class creation.
Correct Answer: b) type
Explanation:
The default metaclass in Python is 'type'.
Correct Answer: b) __getattr__
Explanation:
The __getattr__ method is invoked only when standard attribute lookup fails (attribute is missing).
Correct Answer: a) __getattribute__
Explanation:
The __getattribute__ method intercepts every single attribute access attempt on an instance.
Correct Answer: b) To explicitly declare data members and optimize memory by disabling per-instance __dict__ dictionaries
Explanation:
Using __slots__ prevents the creation of per-instance __dict__ dictionaries, significantly reducing memory overhead for classes with many instances.
Correct Answer: b) Yes, if '__dict__' is explicitly included in the __slots__ tuple
Explanation:
You can include '__dict__' inside __slots__ if you want slot optimization alongside dynamic attribute support.
Correct Answer: b) __setattr__
Explanation:
The __setattr__ special method is called whenever an attribute assignment is attempted.
Correct Answer: c) __delattr__
Explanation:
The __delattr__ method is invoked when an attribute deletion is requested via 'del obj.attr'.
Correct Answer: b) Hiding complex implementation details and showing only essential features to the user
Explanation:
Data abstraction focuses on exposing a simplified interface while concealing internal complexity.
Correct Answer: b) __enter__ and __exit__
Explanation:
A context manager requires implementing both the __enter__ and __exit__ special methods.
Correct Answer: a) The context manager instance itself or a resource proxy
Explanation:
Whatever __enter__ returns is bound to the variable specified after the 'as' clause in the 'with' statement.
Correct Answer: a) exc_type, exc_val, exc_tb
Explanation:
The __exit__ method receives the exception type, exception value, and traceback object if an exception occurs.
Correct Answer: b) Return a true value (such as True)
Explanation:
Returning a true value from __exit__ suppresses any exception that occurred inside the 'with' block.
Correct Answer: a) An attribute shared across all instances of a class
Explanation:
Class attributes belong to the class itself and are shared among all instances.
Correct Answer: a) Instance attributes are unique to each object instance, whereas class attributes are shared
Explanation:
Instance attributes are bound to individual objects, while class attributes belong to the class namespace.
Correct Answer: a) Defining a method in a child class with the same name as a method in its parent class to provide custom behavior
Explanation:
Method overriding allows a subclass to provide a specific implementation of a method already defined in its superclass.
Correct Answer: b) No, the latest definition overrides earlier ones in the same scope
Explanation:
Python does not support traditional compile-time method overloading; defining multiple methods with the same name replaces the previous ones.
Correct Answer: a) typing
Explanation:
The 'typing' module provides support for type hints, including the @overload decorator for static analysis tools.
Correct Answer: a) __eq__
Explanation:
The __eq__ special method defines the behavior for the equality operator (==).
Correct Answer: b) __ne__
Explanation:
The __ne__ special method implements the inequality operator (!=).
Correct Answer: a) Dataclasses (@dataclass)
Explanation:
The @dataclass decorator automatically generates boilerplate methods like __init__ and __repr__ for data-centric classes.
Correct Answer: a) dataclasses
Explanation:
The dataclasses module supplies the @dataclass decorator and helper utilities.
Correct Answer: a) By setting @dataclass(frozen=True)
Explanation:
Setting frozen=True in the @dataclass decorator makes instances immutable, raising FrozenInstanceError on modification.
Correct Answer: a) To perform additional initialization logic after the auto-generated __init__ has finished
Explanation:
The __post_init__ method is called at the end of the auto-generated __init__ function for extra initialization or validation.
Correct Answer: a) __hash__
Explanation:
The __hash__ method returns an integer hash value, enabling objects to be stored in hash-based collections like sets and dictionaries.
Correct Answer: b) It becomes unhashable (.__hash__ is set to None)
Explanation:
Defining __eq__ without __hash__ implicitly sets __hash__ to None, making instances unhashable to preserve consistency.
Correct Answer: b) __contains__
Explanation:
The __contains__ method implements membership test operators like 'item in container'.
Correct Answer: b) __getitem__
Explanation:
The __getitem__ method enables indexing and slicing support on container objects.
Correct Answer: a) __setitem__
Explanation:
The __setitem__ method supports item assignment via bracket notation.
Correct Answer: b) __delitem__
Explanation:
The __delitem__ method handles item deletion via bracket notation.
Correct Answer: a) A class designed to provide a specific set of methods for multiple inheritance without being a standalone base class
Explanation:
A mixin provides specialized functionality to be inherited by other classes through composition or multiple inheritance.
Correct Answer: a) An ambiguity that arises when two parent classes inherit from a common grandparent class, causing confusion over which parent's method to inherit
Explanation:
The diamond problem occurs in multiple inheritance hierarchies when a class inherits from two classes that share a common base.
Correct Answer: b) Using C3 Linearization to produce a deterministic Method Resolution Order (MRO)
Explanation:
Python resolves the diamond problem gracefully via C3 linearization, establishing a predictable MRO.
Correct Answer: a) Inheriting method signatures and specifications without necessarily inheriting implementation code
Explanation:
Interface inheritance defines what methods a subclass must implement, often realized via Abstract Base Classes.
Correct Answer: a) Inheriting both method signatures and their concrete implementations from a base class
Explanation:
Implementation inheritance reuses ready-made method logic from parent classes.
Correct Answer: a) dir()
Explanation:
The dir() function returns a list of valid attributes for an object.
Correct Answer: a) vars()
Explanation:
The vars() function returns the __dict__ attribute dictionary of an object.
Correct Answer: a) A class defined inside another class body
Explanation:
An inner class is a class defined within the scope of another enclosing class.
Correct Answer: a) Yes, depending on how it's referenced
Explanation:
Unlike Java, Python inner classes are not automatically tied to an outer instance, so they can be instantiated directly via Outer.Inner().
Correct Answer: a) Dynamic modification of a class or module at runtime
Explanation:
Monkey patching refers to dynamically altering or extending classes or modules at runtime without changing original source code files.
Correct Answer: a) __bool__
Explanation:
The __bool__ special method customizes truth value testing (if obj:); falls back to __len__ if absent.
Correct Answer: a: An object handling a request by delegating responsibility to a helper or composed object
Explanation:
Delegation is a design pattern where an object forwards requests to another helper object to perform tasks.
Correct Answer: a) Controlling access and validation when reading or writing internal attributes
Explanation:
Getters and setters allow you to intercept, validate, or transform attribute access safely.
Correct Answer: a) An object that implements at least one of __get__, __set__, or __delete__
Explanation:
Descriptors control attribute access for other classes when stored as class attributes.
Correct Answer: a) Data descriptors define both __get__ and __set__/__delete__; non-data descriptors define only __get__
Explanation:
Data descriptors override instance dictionaries during attribute lookup, whereas non-data descriptors can be shadowed by instance attributes.
Correct Answer: a) Data descriptors
Explanation:
Properties created using @property define both a getter and a setter, making them data descriptors.
Correct Answer: a) __repr__
Explanation:
The __repr__ method provides the official, unambiguous representation meant for debugging.
Correct Answer: a) __repr__
Explanation:
If __str__ is missing, Python automatically falls back to calling __repr__.
Correct Answer: a) Converting an object state into a byte stream or format for storage or transmission
Explanation:
Serialization transforms live objects into persistent formats like JSON or bytes.
Correct Answer: a) pickle
Explanation:
The 'pickle' module serializes and deserializes arbitrary Python object structures.
Correct Answer: a) __getstate__ and __setstate__
Explanation:
Objects can customize their pickling behavior by implementing __getstate__ and __setstate__.
Correct Answer: a) To customize shallow and deep cloning behavior via copy.copy() and copy.deepcopy()
Explanation:
Implementing __copy__ and __deepcopy__ allows custom objects to define how they are cloned.
Correct Answer: a) A class attribute shared across all instances
Explanation:
Class attributes act as static variables shared across all instances of that class.
Correct Answer: a) Yes, unless __slots__ restricts it
Explanation:
Standard Python instances store attributes in a dynamic __dict__, allowing attributes to be added at runtime.
Correct Answer: a) A design approach where classes have minimal dependencies on one another
Explanation:
Loose coupling minimizes interdependencies, making systems more maintainable and modular.
Correct Answer: a) A design state where classes are highly dependent on each other's internal implementations
Explanation:
Tight coupling means changes in one class force cascading changes in others, which is generally discouraged.
Correct Answer: a) Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
Explanation:
SOLID represents five core principles of robust object-oriented software design.
Correct Answer: a) Objects of a superclass should be replaceable with objects of a subclass without breaking application correctness
Explanation:
LSP ensures that derived classes extend base classes without altering expected behavioral contracts.
Correct Answer: a) Software entities should be open for extension, but closed for modification
Explanation:
The Open/Closed Principle advocates adding new functionality through inheritance or composition rather than editing existing tested code.
Correct Answer: a) A class should have only one reason to change, meaning it should have responsibility over a single part of functionality
Explanation:
The Single Responsibility Principle ensures each class focuses on a single job or concern.
Correct Answer: a) A creational design pattern that uses factory methods to deal with the problem of creating objects without specifying exact classes
Explanation:
Factory methods encapsulate object creation logic, decoupling instantiation from client code.
Correct Answer: a) A design pattern that restricts a class to a single instantiation instance throughout the program
Explanation:
Singleton ensures globally accessible single-instance management.
Correct Answer: a) __new__
Explanation:
The __new__ method is the constructor that creates and returns the new instance, whereas __init__ is merely the initializer.
Correct Answer: a) When subclassing immutable types like int or str, or implementing Singleton patterns
Explanation:
Since immutable objects cannot be modified in __init__, __new__ must be used to customize their creation.
Correct Answer: a) A structural pattern that allows objects with incompatible interfaces to collaborate
Explanation:
Adapters bridge gaps between differing interfaces so disparate classes can work together.
Correct Answer: a) A behavioral pattern where an object (subject) maintains a list of dependents (observers) and notifies them of state changes
Explanation:
The observer pattern establishes publish-subscribe relationships between objects.
Correct Answer: a) A behavioral pattern that enables selecting an algorithm's behavior at runtime from a family of interchangeable algorithms
Explanation:
Strategy patterns encapsulate interchangeable algorithms into separate classes.
Correct Answer: a) By using dataclasses with frozen=True or overriding __setattr__ to raise errors
Explanation:
You can prevent attribute mutation by freezing dataclasses or intercepting assignments in __setattr__.
Correct Answer: a) True
Explanation:
In Python, bool is a subclass of int, so isinstance(True, int) evaluates to True.
Correct Answer: a) __neg__
Explanation:
The __neg__ special method implements unary negation (-).
Correct Answer: a) __pos__
Explanation:
The __pos__ special method implements unary plus (+).
Correct Answer: a) __abs__
Explanation:
The abs() built-in function invokes the __abs__ special method.
Correct Answer: a) An explicit definition of methods an object must have, checked statically via typing.Protocol
Explanation:
Protocols enable structural subtyping (static duck typing) using typing.Protocol.
Correct Answer: a) They are naming conventions (public has no underscore, protected has one underscore, private has double underscores triggering name mangling)
Explanation:
Python relies on programmer discipline ('we are all consenting adults here') backed by naming conventions and name mangling rather than hard access blocks.
Related Posts
New
New
New

Latest Python Operators MCQs
Operators in Python are special symbols and keywords used to manipulate data, perform mathematical computations, make boolean comparisons, and control…
August 27, 2026By MCQs Generator

Latest Python Loops MCQs
Loops in Python provide the fundamental mechanism for executing a block of code repeatedly until a specified condition is met…
August 27, 2026By MCQs Generator

Top Python Fundamentals MCQs & Answers for Beginners
Python is a dynamically typed, high-level programming language created by Guido van Rossum in 1991. Renowned for its clear syntax…
August 27, 2026By MCQs Generator
Related Categories
New












AI & Data Science MCQ
5 topics
By MCQs Generator
New
Arts & Humanities MCQ
4 topics
By MCQs Generator
New
Civil Engineering MCQ
4 topics
By MCQs Generator
New
Commerce & Business MCQ
4 topics
By MCQs Generator
New
Competitive Exams MCQ
5 topics
By MCQs Generator
New
Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator
New
General Knowledge MCQ
2 topics
By MCQs Generator
New
General Science MCQ
4 topics
By MCQs Generator
New
Law & Judiciary MCQ
3 topics
By MCQs Generator
New
Mechanical Engineering MCQ
4 topics
By MCQs Generator
New
Medical & Health Sciences MCQ
4 topics
By MCQs Generator
New
Modern Tech Fields MCQ
3 topics
By MCQs Generator