▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
OOP interview questions
The questions Vizag and Hyderabad recruiters ask, with clear answers.
🎬 Video version coming soon — read it now
OOP questions come up in almost every fresher interview for Python and software roles, in Vizag, Hyderabad, Bengaluru and remote companies alike. Here are the common ones with short, clear answers you can say in your own words.
1. What are a class and an object?
A class is a blueprint that defines attributes and methods. An object is an instance created from it, with its own data. Example: Student is the class; Student("Anil", 8.4) is an object.
2. What is self?
The first parameter of every instance method. It refers to the object the method was called on, so the method can read and change that object's data. Python passes it automatically.
3. What does __init__ do?
It's the initialiser (often called the constructor). Python calls it right after creating an object, to set up the object's starting attributes.
4. What are the four pillars of OOP?
- Encapsulation: keeping data and the methods that use it together, and protecting internal data (in Python,
_nameand@property) - Abstraction: exposing a simple interface and hiding the details, such as
account.withdraw(500)without knowing how the balance is stored - Inheritance: a child class reusing and extending a parent class
- Polymorphism: the same method name behaving appropriately for different classes, such as
describe()on Employee and Manager
5. What is method overriding?
A child class defining a method with the same name as its parent's, to replace or extend it. super() calls the parent's version.
6. Does Python support method overloading?
Not in the Java sense of several methods with the same name and different parameters. In Python the last definition wins. You get the same effect with default arguments or *args.
7. Composition vs inheritance?
Inheritance models "is a" (a Manager is an Employee). Composition models "has a" (a Car has an Engine) by storing objects inside other objects. Prefer composition when the relationship isn't clearly "is a".
8. __str__ vs __repr__?
__str__ is a readable description for users (used by print). __repr__ is an unambiguous description for developers, ideally looking like the code that creates the object.
9. Class attribute vs instance attribute?
10. What is a dataclass?
A decorator that generates __init__, __repr__ and __eq__ from type-annotated fields. Good for classes that mainly hold data.
How to answer well
- Give the definition in one sentence, then a small example
- Write a tiny class on the whiteboard if you're allowed to; it shows real understanding
- If you don't know, say what you do know and how you'd find out. Interviewers respect that more than a bluff
In one line
Know classes, self, __init__, the four pillars, overriding, composition and dataclasses, and answer each with a definition plus a small example.
Share with a friend