/writing/recruiting & ats/python-object-oriented-programming-interview-questions
§ Hiring Tips·16 min read·October 4, 2026

10 Python Object Oriented Programming Interview Questions

O
Olibr TeamHiring Tips
10 Python Object Oriented Programming Interview Questions

10 Python Object Oriented Programming Interview Questions

Python OOP questions show up in almost every technical round, and freshers often stumble on them. Not because the concepts are hard, but because answers sound memorized. If you are hunting for python object oriented programming interview questions, you want short, correct answers with code you can explain line by line.

That is what this list gives you. Each of the 10 questions comes with a plain-language answer and a small code example. They cover the topics interviewers ask most: classes and objects, __init__, inheritance, MRO, polymorphism, encapsulation, and abstraction. If you are searching for python oops interview questions for freshers, start at question one and work down. The order moves from basics to trickier follow-ups.

We work with recruiters at Olibr, so we know what interviewers look for. They rarely want textbook definitions. They want to see that you can reason with a real example and spot where a concept breaks down. Use the answers below as a base, then rewrite them in your own words.

1. What are classes and objects in Python?

Short interview answer

A class is a blueprint that defines the data and behavior a kind of thing has. An object is one instance built from that blueprint, with its own values. Say it in that order and give an example right away.

Every value in Python is an object, including integers, strings, and functions. That is why this is the opening question in most python object oriented programming interview questions, and why interviewers use it to gauge how deeply you understand the language.

A class describes what something is, and an object is one real thing of that kind.

Code example

This is small enough to write on a whiteboard, and it shows the two ideas that matter: one class, many independent objects.

class Candidate:
    def __init__(self, name, skill):
        self.name = name
        self.skill = skill

    def introduce(self):
        return f'{self.name} works with {self.skill}'

c1 = Candidate('Asha', 'Python')
c2 = Candidate('Ravi', 'Java')

print(c1.introduce())  # Asha works with Python
print(c1 is c2)        # False

Point out that Candidate is defined once, while c1 and c2 each hold their own name and skill. Changing one object never touches the other.

Common follow-up questions

Expect the interviewer to probe the basics with these. Short, precise answers score better than long ones.

  • Is a class also an object? Yes. Classes are instances of type, so type(Candidate) returns type.
  • What does c1 is c2 check? Identity. It asks whether both names point to the same object in memory, not whether the values match.
  • What happens when you write Candidate('Asha', 'Python')? Python calls __new__ to create the object, then __init__ to set it up.
  • Can you create an object without __init__? Yes. Python gives every class a default one, and you only write your own when you need to set initial state.

2. What are init and self in Python?

Short interview answer

__init__ is the initializer method. Python runs it automatically right after an object is created, and you use it to set the object's starting data. self is the first parameter of every instance method, and it refers to the specific object the method is working on.

People often call __init__ a constructor, and most python oops interview questions let that slide. The precise answer is that __new__ builds the object and __init__ only initializes it. Also, self is a naming convention, not a keyword, but you should never rename it.

self is how a method knows which object it belongs to.

Code example

This example shows self carrying state between methods, plus a default argument in __init__.

class Recruiter:
    def __init__(self, name, openings=0):
        self.name = name
        self.openings = openings

    def add_opening(self):
        self.openings += 1

r = Recruiter('Meera')
r.add_opening()
print(r.openings)  # 1

Calling r.add_opening() is the same as Recruiter.add_opening(r). Python passes the object as self for you, which is the detail that impresses interviewers most.

Common follow-up questions

Interviewers usually follow with these quick checks, so keep your answers short.

  • Can __init__ return a value? No. It must return None, or Python raises a TypeError.
  • What if you forget self in a method definition? Calling the method raises a TypeError about too many positional arguments.
  • Can a class have two __init__ methods? No. The second one overrides the first. Use default arguments or a class method instead.

3. What is the difference between instance and class variables?

Short interview answer

An instance variable belongs to one object. You usually set it inside __init__ through self, so every object gets its own copy. A class variable belongs to the class itself and is shared by every object created from it.

This shows up in nearly all python object oriented programming interview questions because it tests whether you know where Python stores data. Instance variables live in the object's __dict__, and class variables live in the class's. Python looks at the object first, then falls back to the class.

Instance variables are per object, while class variables are shared by all.

Code example

This class counts recruiters while keeping each name separate.

class Recruiter:
    company = 'Zenith'   # class variable
    count = 0            # class variable

    def __init__(self, name):
        self.name = name # instance variable
        Recruiter.count += 1

r1 = Recruiter('Meera')
r2 = Recruiter('Arjun')
r1.company = 'Acme'      # creates an instance variable

print(Recruiter.count)   # 2
print(r1.company)        # Acme
print(r2.company)        # Zenith

Watch the last assignment, because it is the classic trap. r1.company = 'Acme' does not change the class variable. It creates a new instance variable that shadows the class one, so r2 still sees the original. Write Recruiter.company = 'Acme' to change it for everyone.

Common follow-up questions

Expect these quick probes after your first answer.

  • Why is a mutable class variable risky? If you write skills = [] at class level, all objects share one list, so an append on one object shows up everywhere.
  • How do you check where a variable lives? Compare r1.__dict__ with Recruiter.__dict__. Only instance variables appear in the first.
  • When should you use a class variable? Use it for constants, defaults, and counters that every object should share.

4. What is inheritance and what types does Python support?

Short interview answer

Inheritance lets a child class reuse and extend the attributes and methods of a parent class. It models an "is a" relationship, so a Recruiter is an Employee.

Python supports five types, and unlike Java it allows multiple inheritance directly:

  • Single: one parent, one child.
  • Multilevel: a chain, such as grandparent to parent to child.
  • Multiple: one child with several parents.
  • Hierarchical: several children share one parent.
  • Hybrid: a mix of the above.

Inheritance reuses code through an "is a" relationship.

Code example

This is the single-inheritance pattern that most python object oriented interview questions expect you to write.

class Employee:
    def __init__(self, name):
        self.name = name

    def role(self):
        return 'Employee'

class Recruiter(Employee):
    def __init__(self, name, openings):
        super().__init__(name)
        self.openings = openings

    def role(self):
        return 'Recruiter'

r = Recruiter('Meera', 5)
print(r.name, r.role())          # Meera Recruiter
print(isinstance(r, Employee))   # True

Notice that super().__init__(name) runs the parent initializer, so name is set without duplicating code. The child's role overrides the parent's version.

Common follow-up questions

Expect the interviewer to test the edges, so keep your answers short and exact.

  • What does super() do? It returns a proxy that finds the next class in the lookup order, so you can call parent methods.
  • What is the difference between isinstance and issubclass? The first checks an object, and the second checks a class.
  • What if the child skips super().__init__()? The parent's attributes are never set, which causes AttributeError later.

5. What is MRO and how does Python solve the diamond problem?

Short interview answer

Four wooden blocks connected by string in a diamond shape, each with a numbered tag.

MRO stands for Method Resolution Order. It is the order Python follows when it searches a class and its parents for a method or attribute. You can inspect it with ClassName.__mro__ or ClassName.mro().

The diamond problem appears when a class inherits from two classes that share one parent. Python solves it with C3 linearization, which builds one predictable order where every class appears once and children come before parents. Freshers working through oops concepts in python interview questions often skip this topic, so a clear answer stands out.

MRO is Python's lookup order, and C3 guarantees each class appears once, children before parents.

Code example

Here D inherits from B and C, and both of those inherit from A.

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

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

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

class D(B, C):
    pass

print(D().greet())                      # B
print([k.__name__ for k in D.__mro__])  # ['D', 'B', 'C', 'A', 'object']

Python checks D, then B, then C, then A. B wins because it is listed first in class D(B, C). Swap the bases and C wins, so base order matters.

Common follow-up questions

Interviewers usually move to super() next, so be ready.

  • Does A run twice in a diamond? No. The MRO lists A once, so its code runs once.
  • How does super() relate to MRO? It follows the MRO, not just the direct parent, so each initializer in the chain runs once.
  • When does C3 fail? If the base order contradicts itself, Python raises a TypeError when the class is defined.

6. What is polymorphism in Python?

Short interview answer

Polymorphism means one interface, many forms. The same method name or operator behaves differently depending on the object it is called on. Python delivers this through method overriding, duck typing, and operator overloading with special methods like __add__.

Duck typing is the part that sets freshers apart in python oops programming interview questions. Python does not check an object's type. It only checks whether the object has the method you call, so you need no shared parent class or interface, unlike Java.

If an object has the method you call, Python does not care which class it comes from.

Code example

These two classes are unrelated, yet one function handles both.

class Resume:
    def parse(self):
        return 'Parsing PDF text'

class CsvFile:
    def parse(self):
        return 'Splitting CSV rows'

def run(parser):
    print(parser.parse())

for item in (Resume(), CsvFile()):
    run(item)

The run function never checks a type. Each object works because it defines parse, which makes this polymorphism without inheritance. Built-ins do the same, since len() works on strings, lists, and dictionaries, and + adds numbers or joins strings.

Common follow-up questions

Expect a quick comparison question here, since it is a favorite in oops interview questions in python for freshers.

  • Does Python support method overloading? Not like Java. A second method with the same name replaces the first. Use default arguments, *args, or functools.singledispatch instead.
  • What is the difference between overriding and overloading? Overriding means a child class redefines a parent method. Overloading means one name accepts different argument patterns.
  • What is operator overloading? You define __add__ or __eq__ so that + and == work on your own objects.

7. What is encapsulation and how does Python implement it?

Short interview answer

Encapsulation means bundling data and the methods that use it inside one class, then controlling how outside code touches that data. It protects an object from being put into an invalid state.

Python has no true private keyword, so it relies on naming conventions:

  • name: public, free to use.
  • _name: protected by convention, meaning "internal, please don't touch."
  • __name: name-mangled to _ClassName__name, which makes accidental access harder.

This comes up in most python object oriented programming interview questions, and the winning answer admits the limits.

Python encapsulation is a convention backed by name mangling, not a lock.

Code example

This class hides the balance and validates every change through a method.

class Account:
    def __init__(self, owner, balance):
        self.owner = owner
        self.__balance = balance

    @property
    def balance(self):
        return self.__balance

    def deposit(self, amount):
        if amount <= 0:
            raise ValueError('Amount must be positive')
        self.__balance += amount

a = Account('Meera', 1000)
a.deposit(500)
print(a.balance)           # 1500
print(a._Account__balance) # 1500, mangling is not security

Reading a.__balance raises AttributeError, yet the mangled name still works. Say so, because it shows you know privacy here is by agreement.

Common follow-up questions

Expect these quick probes next.

  • What does @property do? It lets you expose a method as an attribute, so you can add validation later without changing callers.
  • Single vs double underscore? One signals intent only. Two triggers name mangling, which avoids clashes in subclasses.
  • How do you make an attribute read-only? Define a @property with no setter.

8. What is abstraction and how do abstract classes work?

Short interview answer

Abstraction means showing what an object does while hiding how it does it. In Python you enforce it with the abc module. An abstract class inherits from ABC and marks required methods with @abstractmethod.

Interviewers like this one in python object oriented programming interview questions because it separates the contract from the implementation. You cannot create an object from a class that still has abstract methods, so every subclass must override all of them first.

An abstract class defines the contract, and its subclasses supply the work.

Code example

This base class forces every sourcing channel to implement fetch.

from abc import ABC, abstractmethod

class Source(ABC):
    @abstractmethod
    def fetch(self):
        pass

class JobBoard(Source):
    def fetch(self):
        return 'Fetching board listings'

class Referral(Source):
    pass

print(JobBoard().fetch())  # Fetching board listings
Referral()  # TypeError: Can't instantiate abstract class

Referral fails because it never defines fetch. Python raises the error when you instantiate, not when the class is defined, and saying that aloud shows you have actually run this code.

Common follow-up questions

Expect these two comparisons first, since interviewers love them.

  • Abstraction vs encapsulation? Abstraction hides complexity at the design level. Encapsulation protects the data inside a class.
  • Can an abstract class have normal methods? Yes. It can mix concrete methods and a shared __init__ with abstract ones.
  • Is there an interface keyword? No. An abstract class with only abstract methods plays that role, and typing.Protocol gives a duck-typed alternative.

9. How do class methods, static methods and instance methods differ?

Short interview answer

Hub diagram linking instance, class, and static methods to the center of a class.

An instance method takes self and works on one object's data. A class method takes cls, carries the @classmethod decorator, and works on the class itself. A static method takes neither and is just a plain function that lives inside the class for organization.

Type First argument Can access
Instance method self Object and class data
Class method cls Class data only
Static method None Nothing implicitly

Interviewers include this in python oops interview questions because the alternate constructor pattern shows real experience. A class method receives the class, so it can build and return objects, and subclasses get the right type automatically.

Use self for object data, cls for class data, and neither when the function needs no state.

Code example

class Candidate:
    def __init__(self, name, skill):
        self.name = name
        self.skill = skill

    @classmethod
    def from_string(cls, text):
        name, skill = text.split(',')
        return cls(name, skill)

    @staticmethod
    def is_valid_skill(skill):
        return len(skill) > 1

c = Candidate.from_string('Asha,Python')
print(c.name)                          # Asha
print(Candidate.is_valid_skill('Go'))  # True

Notice that from_string returns cls(name, skill) instead of hardcoding Candidate. That keeps it subclass-friendly, and is_valid_skill stays static because it touches no object or class state.

Common follow-up questions

Expect these short checks next.

  • When do you use a class method? For alternate constructors, or when you need to change a class variable.
  • Can you call a static method on an object? Yes, c.is_valid_skill('Go') works, but calling it through the class is clearer.
  • Why not make everything static? Static methods cannot see self or cls, so they cannot use object or class data without it being passed in.

10. What is the difference between composition and inheritance?

Short interview answer

A modular figure with detachable envelope and calendar parts, plus a spare module nearby.

Inheritance models an "is a" relationship, so a Recruiter is an Employee. Composition models a "has a" relationship, so a Recruiter has a Scheduler. The class stores other objects as attributes and hands work to them.

The usual advice, and a strong closing answer in python object oriented programming interview questions, is to favor composition over inheritance. Deep chains tie a child tightly to its parents, so one change high up can break everything below. Composition keeps parts small and swappable.

Use inheritance for "is a", use composition for "has a", and pick composition when unsure.

Code example

Here the recruiter uses an emailer and a scheduler instead of inheriting from them.

class Emailer:
    def send(self, to, msg):
        return f'Email to {to}: {msg}'

class Scheduler:
    def book(self, name):
        return f'Interview booked for {name}'

class Recruiter:
    def __init__(self, name):
        self.name = name
        self.emailer = Emailer()
        self.scheduler = Scheduler()

    def invite(self, candidate):
        print(self.scheduler.book(candidate))
        print(self.emailer.send(candidate, 'See you soon'))

Recruiter('Meera').invite('Asha')

Because Recruiter only holds its parts, you can replace Emailer with an SMS sender in one line. No parent class changes, and there is no MRO to untangle.

Common follow-up questions

Expect the interviewer to ask you to defend your choice.

  • When is inheritance the right choice? When the child truly is a specialized version of the parent and keeps its contract, like JobBoard and Source.
  • What goes wrong with deep hierarchies? Changes ripple downward, and the MRO becomes hard to reason about.
  • Is composition the same as aggregation? Almost. Creating the parts inside __init__, as above, is composition. Passing them in from outside is aggregation, and it makes testing easier.

Preparing for your Python OOP interview

Python OOP interviews reward clarity over cramming. Across these python object oriented programming interview questions, the pattern repeats: give a one-line definition, show a small code example, then explain where the concept breaks. That approach works for every topic, from __init__ to MRO and abstraction.

Next, practice out loud. Type each example from memory, change one line, and predict the output before you run it. If you can explain why the result changed, you are ready for the follow-ups. You will also sound like someone who writes code rather than recites it.

Finally, put that preparation in front of people who hire. Olibr lets you create a free candidate profile, get matched to tech roles by AI, and be discovered by 500+ recruiters. Build the profile once, then let your Python skills do the work.

For engineers

Find work worth your time.

Live engineering roles across India and the US, matched to your stack. Build a profile recruiters actually discover.

Browse jobsHow it works

O
§ The author

Olibr Team

Reviewed by Raman Gupta, Founder, Olibr

Filed underHiring Tips
Reading time16 min · 3,113 words

PublishedOctober 4, 2026

CategoryHiring Tips
Enjoyed this piece?Share it with someone who would find it useful.
§ Stay in the loop

Don’t miss the next one.

We publish essays on engineering, hiring, and building teams. Subscribe and we’ll send them when they land.

Unsubscribe anytime · one letter, never more