oops interview questions — the short answer
most OOPs interview questions test six things: the four pillars (encapsulation, abstraction, inheritance, polymorphism), class vs object, overloading vs overriding, abstract class vs interface, constructors, and access modifiers. if you can explain these in plain words and back each one with a 5-line code example, you'll clear the OOPs part of most fresher rounds.
experienced rounds go one level up. they ask about composition vs inheritance, SOLID, design patterns, and "model this system in classes" problems.
this guide has 40 questions in that order: basics, intermediate, then experienced and design. every answer is short enough to say out loud in an interview. code is in java (the most common interview language in india), with python and c++ notes where the languages differ.
what interviewers actually ask (real reports, not guesses)
we went through recent fresher interview reports on AmbitionBox. the same questions keep coming back. candidates at TCS java developer fresher interviews reported "what is polymorphism?" and "what is compile time and runtime polymorphism?". candidates at Infosys system engineer interviews reported "explain the four pillars of OOP" and "what is encapsulation?" again and again.
here's how the depth changes by company type:
| company type | what the OOPs round looks like | example question |
|---|---|---|
| service companies (TCS, Infosys, Wipro, Cognizant) | definitions plus one example per concept. usually 5–10 minutes inside the technical round. | "what is the difference between overloading and overriding?" |
| product companies | concepts plus "why". they push on trade-offs and edge cases. | "why can't java have multiple inheritance of classes?" |
| startups | less theory, more code. you may be asked to design classes for a small feature live. | "design the classes for a food delivery order." |
| experienced / SDE-2+ | design patterns, SOLID, low-level design (LLD). | "design a parking lot. which patterns would you use?" |
a. oops basics — the questions every fresher gets
1. what is object-oriented programming?
OOP is a way of writing code where you group data and the functions that work on that data into one unit called an object.
example: a bank app doesn't keep a loose balance variable and a separate withdraw() function. it has an Account object that holds the balance and knows how to withdraw from it.
2. what are the four pillars of OOP?
| pillar | one-line meaning | everyday example |
|---|---|---|
| encapsulation | keep data private, expose only safe methods | you can't edit your bank balance directly, only deposit or withdraw |
| abstraction | show what something does, hide how it does it | you press "pay" on UPI without knowing the bank-to-bank steps |
| inheritance | a class reuses another class's code | SavingsAccount gets everything Account has |
| polymorphism | one method name, different behaviour | calculateInterest() works differently for savings and FD accounts |
tip: interviewers like it when you use one running example (like the bank) for all four. it shows you understand how they connect.
3. what is the difference between a class and an object?
a class is the blueprint. an object is a real thing built from it.
example: Car is the class. your red Swift with number KA-01-1234 is an object. one class, many objects. a class takes no memory for data until you create an object.
class Car {
String model;
int speed;
}
Car myCar = new Car(); // object created here
myCar.model = "Swift";
4. what is encapsulation?
encapsulation means wrapping data and methods together and blocking direct access to the data. you make fields private and give controlled access through methods.
class Account {
private double balance;
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
}
}
public double getBalance() {
return balance;
}
}
nobody outside can set balance = -5000. the class protects its own rules.
5. what is abstraction, and how is it different from encapsulation?
this is the most confused pair in OOPs interviews. keep it simple:
- abstraction is about design: what should the user see? (a
sendNotification()method) - encapsulation is about protection: how do we stop misuse of the data? (private fields, getters, setters)
example: a TV remote. abstraction is the buttons you get (power, volume). encapsulation is the sealed case that stops you from touching the circuit board.
6. what is inheritance?
inheritance lets a child class reuse the fields and methods of a parent class. it models an "is-a" relationship.
class Employee {
String name;
double baseSalary;
}
class Manager extends Employee { // Manager is-a Employee
int teamSize;
}
7. what are the types of inheritance?
- single: B extends A
- multilevel: C extends B, B extends A
- hierarchical: B and C both extend A
- multiple: C extends both A and B
- hybrid: a mix of the above
java classes support single, multilevel and hierarchical. java gets "multiple" only through interfaces. c++ and python support multiple inheritance of classes directly.
8. what is polymorphism?
polymorphism means "many forms". the same method call behaves differently depending on the object.
Shape s1 = new Circle();
Shape s2 = new Square();
s1.draw(); // draws a circle
s2.draw(); // draws a square
the calling code doesn't care which shape it has. that's the real benefit: you can add a Triangle later without touching the code that calls draw().
9. what is compile-time vs runtime polymorphism?
| compile-time (static) | runtime (dynamic) | |
|---|---|---|
| achieved by | method overloading | method overriding |
| decided when | when the code compiles | when the program runs |
| based on | method signature (parameters) | actual object type |
| example | add(int, int) vs add(double, double) | Circle.draw() vs Square.draw() |
10. what is the difference between method overloading and overriding?
- overloading: same method name, different parameters, usually in the same class. example:
print(int x)andprint(String s). - overriding: child class gives its own version of a parent method with the same signature. example:
DogoverridesAnimal.makeSound().
trap question: "can you overload by changing only the return type?" no. the compiler can't tell which one you mean, so java won't compile it.
python note: python has no true overloading. if you define two methods with the same name, the second one replaces the first. people use default arguments or functools.singledispatch instead.
11. what is a constructor?
a constructor is a special method that runs automatically when an object is created. it sets the starting values. it has the same name as the class and no return type (in java and c++). in python it's __init__.
class Student {
String name;
Student(String name) {
this.name = name;
}
}
12. what are the types of constructors?
- default constructor: no parameters. java adds one for you if you write no constructor at all.
- parameterised constructor: takes values, like
Student(String name). - copy constructor: builds a new object from an existing one. built into c++. in java you write it yourself.
13. what is a destructor? does java have one?
a destructor cleans up when an object is destroyed. c++ has real destructors (~ClassName()). java does not. java's garbage collector frees memory on its own. the old finalize() method is deprecated, so don't suggest it. for files and connections, use try-with-resources. python has __del__, but you shouldn't rely on when it runs.
14. what are access modifiers?
| modifier (java) | same class | same package | subclass | everywhere |
|---|---|---|---|---|
private | yes | no | no | no |
| default (no keyword) | yes | yes | no (outside package) | no |
protected | yes | yes | yes | no |
public | yes | yes | yes | yes |
python has no enforced modifiers. a single underscore (_name) means "internal, please don't touch". a double underscore (__name) triggers name mangling, so it gets renamed to _ClassName__name.
15. what do this and super mean?
thispoints to the current object. you use it when a parameter has the same name as a field:this.name = name.superpoints to the parent class. use it to call the parent's constructor (super(name)) or the parent's version of an overridden method.
16. what does static mean?
a static field or method belongs to the class, not to any one object. example: Student.totalStudents is one shared counter, while each student still has their own name. a static method can't use this because there's no object.
practising these out loud is the fastest way to stop blanking in interviews. paste the job description into weekday's free interview question predictor. it ranks the questions you're most likely to get for that role and gives you sample answers. no sign-up needed.
b. intermediate oops questions — where most candidates slip
17. what is an abstract class?
an abstract class is a class you can't create objects of. it exists to be extended. it can have both finished methods and abstract (empty) methods that children must fill in.
abstract class Payment {
abstract void pay(double amount); // child must implement
void printReceipt() { // shared logic
System.out.println("receipt printed");
}
}
class UpiPayment extends Payment {
void pay(double amount) { /* UPI logic */ }
}
18. what is an interface?
an interface is a contract. it lists what a class must do, not how. a class can implement many interfaces. since java 8, interfaces can also have default and static methods with a body.
19. abstract class vs interface — when do you use which?
this is asked in almost every java round. the official java tutorial puts the core difference simply: abstract classes can hold normal fields and non-public methods, while interface fields are always public, static and final.
| abstract class | interface | |
|---|---|---|
| how many can a class use? | only one (extends) | many (implements) |
| fields | any kind | only constants (public static final) |
| constructor | yes | no |
| use it when | classes share code and state ("is-a") | unrelated classes share a capability ("can-do") |
| example | Vehicle → Car, Bike | Payable → Invoice, Salary |
simple rule: if you're sharing code, use an abstract class. if you're sharing a promise, use an interface.
20. why doesn't java support multiple inheritance of classes?
to avoid the diamond problem. say classes B and C both extend A and both override show(). if D extends both B and C, which show() should D get? java avoids the confusion by allowing only one parent class. c++ allows it and solves the clash with virtual inheritance. python allows it and picks the method using its method resolution order (MRO).
21. what is the difference between is-a and has-a?
- is-a = inheritance. a
Caris aVehicle. - has-a = composition. a
Carhas anEngine.
22. why is composition often preferred over inheritance?
inheritance locks the child to the parent. change the parent and every child may break. composition is looser: you plug objects together and can swap parts.
example: instead of ElectricCar extends Car and PetrolCar extends Car, give Car an Engine field. now you can pass in an ElectricEngine or a PetrolEngine without creating a new class for every combination.
23. what is association, aggregation and composition?
| relationship | meaning | example | if the owner is deleted… |
|---|---|---|---|
| association | two objects know each other | teacher ↔ student | both live on |
| aggregation | weak "has-a" | department has professors | professors still exist |
| composition | strong "has-a" | house has rooms | rooms are gone too |
24. what is static vs dynamic binding?
static binding links a method call to its code at compile time. private, static and final methods work this way. dynamic binding links it at runtime based on the real object. overridden methods work this way. this is the engine behind runtime polymorphism.
25. what is a virtual function?
a c++ term. a method marked virtual in the base class can be overridden, and the right version is picked at runtime through a vtable. in java every non-static, non-final, non-private method is virtual by default, so you don't write the keyword.
26. what is upcasting and downcasting?
- upcasting: treating a child as its parent.
Animal a = new Dog();it's always safe. - downcasting: going back to the child type.
Dog d = (Dog) a;it's risky, because ifais actually aCatyou get aClassCastException. check withinstanceoffirst.
27. what does final do?
finalvariable: value can't change after it's setfinalmethod: can't be overriddenfinalclass: can't be extended (example:String)
28. what is an immutable object?
an object whose state never changes after creation. java's String is the classic example. to build one: make the class final, fields private final, give no setters, and return copies of any mutable fields. immutable objects are thread-safe by default, which is why interviewers love this question.
29. shallow copy vs deep copy?
a shallow copy copies the object but shares the objects inside it. a deep copy copies everything, all the way down.
example: you copy a Team object that holds a list of players. with a shallow copy, adding a player to the copy also adds them to the original, because both share one list. with a deep copy they're fully separate.
30. what are the method overriding rules in java?
- same name and same parameters
- return type must be the same or a subtype (covariant return)
- access can't be more restrictive (you can't override a
publicmethod asprivate) - can't override
static,finalorprivatemethods - can't throw broader checked exceptions than the parent
c. experienced and design questions
31. what are the SOLID principles?
| letter | principle | in plain words |
|---|---|---|
| S | single responsibility | one class, one job. InvoicePrinter shouldn't also send emails. |
| O | open/closed | add new behaviour by adding code, not by editing old code |
| L | liskov substitution | a child should work anywhere the parent works |
| I | interface segregation | many small interfaces beat one giant one |
| D | dependency inversion | depend on interfaces, not on concrete classes |
32. give an example of breaking the liskov substitution principle
the classic one: Square extends Rectangle. a rectangle lets you set width and height separately. a square can't. code that sets width to 5 and height to 10 and expects area 50 gets 100 with a square. the child broke the parent's promise, so it shouldn't inherit from it.
33. what are design patterns? name a few you've used
design patterns are tested answers to common design problems. the three groups are creational, structural and behavioural. safe ones to talk about:
- singleton: only one instance (a config manager)
- factory: creates objects without exposing which class (a
NotificationFactoryreturning email or SMS) - builder: builds complex objects step by step (an HTTP request)
- strategy: swaps algorithms at runtime (different discount rules)
- observer: notifies many listeners when something changes (order status updates)
tip: only name patterns you've actually used. the follow-up is always "where did you use it?"
34. how do you write a thread-safe singleton?
the simplest safe version in java is an enum: enum Config { INSTANCE; }. the other common answer is the holder-class pattern. also mention the downsides: singletons are hard to test and hide dependencies, so many teams use dependency injection instead.
35. what is dependency injection?
instead of a class creating its own dependencies, they're passed in from outside.
example: OrderService receives a PaymentGateway in its constructor instead of doing new RazorpayGateway() inside. now you can pass a fake gateway in tests. spring boot is built around this idea, which is why it comes up in spring boot interviews too.
36. what is coupling and cohesion?
coupling is how much classes depend on each other. you want it low. cohesion is how focused one class is on a single job. you want it high. good OOP design is "low coupling, high cohesion".
37. what is a god object, and how do you fix it?
a god object is one class that does everything: a 3,000-line AppManager handling users, payments and emails. fix it by splitting by responsibility (UserService, PaymentService, EmailService) and connecting them through interfaces.
38. when should you not use inheritance?
- when the relationship is "has-a", not "is-a"
- when you only want to reuse one or two methods
- when the hierarchy would go more than 2–3 levels deep
- when the parent class is likely to change often
d. scenario questions — the ones that decide the offer
39. design the classes for a parking lot
don't jump into code. talk through it in this order:
- clarify: how many floors? what vehicle types? hourly pricing?
- list the nouns:
ParkingLot,Floor,ParkingSpot,Vehicle,Ticket,Payment - add the relationships: a lot has floors, a floor has spots (composition).
Car,BikeandTruckextendVehicle. - find the variation points: pricing differs by vehicle, so make it a
PricingStrategyinterface (strategy pattern). - walk one flow: car enters → find a free spot → issue a ticket → exit → calculate fee → pay.
interviewers grade the thinking more than the final diagram.
40. what's wrong with this code?
class Bird {
void fly() { System.out.println("flying"); }
}
class Penguin extends Bird {
void fly() { throw new UnsupportedOperationException(); }
}
answer: it breaks liskov substitution. any code that calls bird.fly() will crash for a penguin. a better design: Bird holds what all birds share, and a separate Flyable interface is implemented only by birds that fly.
oops cheat sheet — java vs python vs c++
| feature | java | python | c++ |
|---|---|---|---|
| multiple inheritance of classes | no (interfaces only) | yes (MRO) | yes (virtual inheritance for diamonds) |
| method overloading | yes | no (last definition wins) | yes |
| access modifiers | private, default, protected, public | by convention (_, __) | private, protected, public |
| abstract classes | abstract keyword | abc module | pure virtual functions (= 0) |
| destructor | no (garbage collector) | __del__ (unreliable timing) | yes (~ClassName) |
| everything is an object? | no (primitives exist) | yes | no |
mistakes that cost candidates the OOPs round
- reciting textbook lines. "abstraction is hiding implementation details" with no example sounds memorised. always add a real one.
- mixing up abstraction and encapsulation. use the TV remote example from Q5 and you won't.
- saying java supports multiple inheritance. only through interfaces. say that clearly.
- overusing inheritance in design rounds. five levels of classes is a red flag. mention composition.
- naming design patterns you've never used. the follow-up question will expose it.
- not knowing your own resume. if your project says "used OOP principles", expect "show me where".
a 7-day oops prep plan
| day | focus | do this |
|---|---|---|
| 1 | class, object, constructors | write a Student class with 3 constructors |
| 2 | encapsulation and abstraction | build an Account class that blocks bad withdrawals |
| 3 | inheritance and polymorphism | Shape → Circle, Square with an overridden area() |
| 4 | abstract class vs interface | model payments: abstract Payment plus a Refundable interface |
| 5 | SOLID | refactor one old college project using two of the principles |
| 6 | design patterns | code a factory and a strategy from scratch |
| 7 | mock round | explain all 40 answers out loud in 60 minutes and time yourself |
if your interview is java-heavy, pair this with our 50 java interview questions and core java questions. for python roles, see our python interview questions. both have full OOP sections. c# developers can use our c# interview questions.
faqs about oops interview questions
what are the 4 basic concepts of OOPs?
encapsulation, abstraction, inheritance and polymorphism. some lists also add class, object and message passing, which is where "7 concepts of OOPs" comes from.
which language is best for OOPs interviews?
use the language on your resume. java is the most common in indian service-company interviews because it forces you to use classes. python and c++ are fine if that's what you know well. just know the differences in the cheat sheet above.
are OOPs questions asked for non-developer roles?
yes, at a basic level. QA, data analyst and support engineer roles at IT services companies often get "what is OOPs?" and "explain inheritance" in the technical round.
how many OOPs questions should a fresher prepare?
sections a and b (questions 1–30) cover nearly every fresher round. learn those deeply instead of skimming 100 questions.
is low-level design (LLD) the same as OOPs?
LLD is OOPs applied to a real problem. you use classes, relationships and patterns to design something like a parking lot or a BookMyShow booking flow. experienced roles usually have a separate LLD round.
ready for the real interview?
knowing OOPs gets you through the round. getting the interview comes first. upload your resume to weekday and get matched with companies hiring for your skills. browse open java developer jobs or remote backend jobs in india to see what companies are asking for right now.




