100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

OOP Interview Questions in Python

Deep-dive interview questions on Python's object-oriented programming concepts: classes, inheritance, polymorphism, and more.

Concurrency & Interview PrepIntermediate18 min readJul 7, 2026
Analogies

1. Overview

This roundup focuses strictly on object-oriented programming concepts in Python -- classes, inheritance, polymorphism, encapsulation, abstraction, and the special (magic) methods that make custom objects behave like built-ins. These are among the most common technical interview topics for any Python role that involves designing classes, so work through the tracing questions carefully.

🏏

Cricket analogy: Just as a fast bowler's interview covers grip, seam position, and follow-through, this roundup drills into classes, inheritance, polymorphism, encapsulation, and abstraction -- the core technical vocabulary any Python OOP candidate must trace precisely.

2. Frequently Asked Questions

What are the four pillars of OOP, and how does Python support each?

Encapsulation bundles data and methods together in a class, restricting direct access via naming conventions (single/double underscore prefixes). Inheritance lets a class (subclass) reuse and extend another class's (superclass's) attributes and methods. Polymorphism allows objects of different classes to be used interchangeably through a common interface, typically via method overriding. Abstraction hides implementation detail behind a simpler interface, often via abstract base classes (the abc module) that define required methods without implementing them.

🏏

Cricket analogy: A franchise bundles its playing XI's strategy with its team management (encapsulation), a junior academy inherits senior team drills (inheritance), any batter can 'play a cover drive' differently based on skill (polymorphism), and a scoreboard shows only the final total, hiding the underlying sensor logic (abstraction).

What is the difference between a class method, static method, and instance method?

An instance method takes self as its first parameter and operates on a specific instance's state. A class method, marked with @classmethod, takes cls as its first parameter and operates on the class itself (often used for alternative constructors). A static method, marked with @staticmethod, takes neither self nor cls -- it behaves like a plain function that's just namespaced inside the class for organizational purposes.

🏏

Cricket analogy: A player's personal batting technique is like an instance method acting on that player's own form (self); a national selector's decision method acts on the whole team roster (cls, classmethod, used for picking a squad); and a groundskeeper's mowing routine is a static method -- namespaced under 'stadium operations' but needing no player or team context.

What is the output of the following code?

python
class A:
    def greet(self):
        return "A"

class B(A):
    def greet(self):
        return "B" + super().greet()

class C(A):
    def greet(self):
        return "C" + super().greet()

class D(B, C):
    pass

print(D().greet())

D's Method Resolution Order (via C3 linearization) is D -> B -> C -> A -> object. Calling D().greet() uses B's greet(), which returns "B" + super().greet(). Because super() follows D's MRO (not B's own parent chain), the next class after B in that MRO is C, so it calls C.greet(), returning "C" + super().greet(), whose super() now resolves to A, returning "A". Unwinding: "C" + "A" = "CA", then "B" + "CA" = "BCA". Output: BCA.

🏏

Cricket analogy: Tracing a fielding rotation D -> B -> C -> A, B fields first and calls the next fielder in the rotation, not B's own backup, so it goes to C, then to A, and the relay of catches back up the chain reads B-C-A combined into 'BCA'.

What is Method Resolution Order (MRO) and how does Python compute it?

MRO is the order in which Python searches base classes when looking up a method or attribute on an object, especially important with multiple inheritance. Python uses the C3 linearization algorithm, which produces a consistent order where a class always appears before its parents, and the order of parents in the class definition is preserved. You can inspect it via ClassName.__mro__ or ClassName.mro().

🏏

Cricket analogy: MRO is like a fixed batting order the umpire consults to decide who plays a contested shot first -- a batter's own record is checked before the team's, before the league's, in a consistent, predictable sequence set at the toss.

What is the difference between `__str__` and `__repr__`?

__str__ should return a readable, user-friendly string representation of an object (used by print() and str()). __repr__ should return an unambiguous, developer-facing representation, ideally one that could recreate the object (used by the REPL and repr()). If __str__ is not defined, Python falls back to __repr__.

🏏

Cricket analogy: __str__ is like a scoreboard showing 'India 245/6' for fans (readable), while __repr__ is like the official scorer's detailed log entry precise enough to reconstruct the exact ball-by-ball state for the record books.

What is encapsulation, and how is it achieved in Python given there are no truly private members?

Encapsulation means bundling data with the methods that operate on it and controlling access to that data. Python has no enforced access modifiers like Java's private; instead it uses convention: a single leading underscore (_attr) signals 'protected, internal use only' by convention, and a double leading underscore (__attr) triggers name mangling to _ClassName__attr, making accidental external access harder (though not impossible).

🏏

Cricket analogy: A team bundles its playing strategy with the coach who applies it (encapsulation); a single-underscore _bench_players signals 'internal squad list, don't touch' by convention, while a double-underscore __team_signals gets name-mangled so opposing teams can't easily read the private hand signals.

What is the difference between method overloading and method overriding in Python?

Method overriding means a subclass redefines a method that's already defined in its superclass, changing its behavior for that subclass -- Python supports this directly. Method overloading (multiple methods with the same name but different signatures) is not natively supported in Python; instead you simulate it with default arguments, *args/**kwargs, or the functools.singledispatch decorator.

🏏

Cricket analogy: Method overriding is like a franchise team redefining the national team's fielding drill for its own style, directly supported; overloading -- picking a bowler by 'name only' versus 'name and pace' -- isn't natively supported, so Python simulates it with default arguments instead.

What is a Python abstract base class and how do you define one?

An abstract base class (ABC) defines a common interface that subclasses must implement, but cannot be instantiated itself. You create one by inheriting from abc.ABC and marking required methods with @abstractmethod; attempting to instantiate a subclass that hasn't implemented all abstract methods raises a TypeError.

🏏

Cricket analogy: An abstract base class is like a league rulebook defining that every franchise 'must field a captain', without itself being a playable team; a franchise that skips naming a captain can't take the field -- the equivalent of a TypeError at instantiation.

What does `self` refer to and why must it be the first parameter of instance methods?

self refers to the specific instance the method was called on. It's not a reserved keyword -- it's a strong convention -- but Python automatically passes the instance as the first argument to any instance method (obj.method(args) is really Class.method(obj, args)), so the first parameter must be there to receive it.

🏏

Cricket analogy: self is like the specific batter currently facing the bowler -- the umpire (Python) automatically knows which batter is 'on strike' and passes that context first, even though 'self' isn't shouted aloud, it's just understood convention.

What is operator overloading, and how would you implement `+` for a custom Vector class?

Operator overloading lets custom objects respond to built-in operators like +, ==, or < by defining the corresponding magic method. For +, you implement __add__(self, other), returning a new object representing the result, e.g., def __add__(self, other): return Vector(self.x + other.x, self.y + other.y).

🏏

Cricket analogy: Operator overloading lets a custom 'PartnershipScore' object respond to + by defining __add__, so batter1_runs + batter2_runs combines both into a partnership total, e.g. def __add__(self, other): return Partnership(self.runs + other.runs).

3. Quick Reference

  • MRO uses C3 linearization; check it with ClassName.__mro__.
  • @staticmethod takes neither self nor cls; @classmethod takes cls and can access/modify class state.
  • __init__ initializes an already-created instance; __new__ actually creates the instance (rarely overridden).
  • Single leading underscore = 'protected' by convention; double leading underscore = name-mangled ('private'-ish).
  • Implement magic methods like __add__, __eq__, __str__, __repr__ to make custom objects behave like built-ins.

4. Key Takeaways

  • The four OOP pillars -- encapsulation, inheritance, polymorphism, abstraction -- all have concrete Python mechanisms.
  • Python resolves multiple inheritance via C3-linearized MRO, and super() follows that MRO, not a naive parent chain.
  • Python has no true private attributes; double-underscore name mangling is a convention-based safeguard, not real access control.
  • Method overriding is native to Python; method overloading is simulated via default args, *args/**kwargs, or singledispatch.
  • Abstract base classes (via abc.ABC and @abstractmethod) enforce that subclasses implement required methods.

Practice what you learned

Was this page helpful?

Topics covered

#Python#PythonProgrammingStudyNotes#Programming#OOPInterviewQuestionsInPython#OOP#Interview#Questions#Frequently#StudyNotes#SkillVeris