"Explain the four pillars of OOP." It sounds like an easy question, until the interviewer follows up with "Now give me a real example," then "What's the difference between an abstract class and an interface?" and "Why doesn't Java support multiple inheritance?"
OOPs (Object-Oriented Programming) is one of the most commonly tested topics in fresher technical interviews, at both service and product companies. This guide covers the top 20 OOPs interview questions for freshers in 2026, with simple explanations, Java examples and the follow-ups interviewers love to ask.
Basic OOPs Interview Questions
1. What is Object-Oriented Programming?
OOP is a programming approach that organises code around objects: entities that combine data (fields) and behaviour (methods). It makes code easier to reuse, extend and maintain. Java, C++, Python and C# all support OOP.
2. What are the four pillars of OOP?
Encapsulation: Bundling data and methods together and restricting direct access to data
Abstraction: Showing only essential features and hiding implementation details
Inheritance: One class acquiring properties and behaviour of another
Polymorphism: One interface, many forms. The same method behaves differently depending on the object.
3. What is the difference between a class and an object?
A class is a blueprint that defines fields and methods. An object is an instance of that class, created in memory. For example, Car is a class, and a specific red car with a number plate is an object.
4. What is encapsulation? Give an example.
Encapsulation means keeping fields private and controlling access through public methods, so data can't be changed in invalid ways.
class BankAccount {
private double balance;
public void deposit(double amount) {
if (amount > 0) balance += amount;
}
public double getBalance() {
return balance;
}
}No one can set the balance to a negative number directly. They must go through deposit().
Practice
Practice this interview before the real one
Answer real interview questions out loud and get feedback on every answer from an AI interviewer.
5. What is abstraction?
Abstraction hides complex implementation and exposes only what's necessary. When you drive a car, you use the steering wheel and pedals without knowing how the engine works. In Java, abstraction is achieved with abstract classes and interfaces.
6. What is the difference between an abstract class and an interface?
Abstract class | Interface |
|---|---|
Can have abstract and concrete methods | Mainly abstract methods; Java 8+ also allows default and static methods |
Can have instance variables with any access modifier | Variables are public, static and final by default |
Can have constructors | Cannot have constructors |
A class can extend only one abstract class | A class can implement multiple interfaces |
Use for closely related classes sharing code | Use to define a capability many unrelated classes can have |
7. What is inheritance? What are its types?
Inheritance lets a class (child) reuse fields and methods of another class (parent) using the extends keyword in Java.
Single: One child, one parent
Multilevel: A chain (A → B → C)
Hierarchical: Multiple children share one parent
Multiple: One class with multiple parents. In Java, this is only possible through interfaces.
8. What is polymorphism? What are its types?
Compile-time polymorphism (method overloading): Same method name, different parameters, decided at compile time.
Runtime polymorphism (method overriding): A child class provides its own version of a parent method, decided at runtime based on the object.
class Animal {
void sound() { System.out.println("Some sound"); }
}
class Dog extends Animal {
@Override
void sound() { System.out.println("Bark"); }
}
Animal a = new Dog();
a.sound(); // prints "Bark" (runtime polymorphism)9. What is the difference between method overloading and overriding?
Overloading | Overriding |
|---|---|
Same method name, different parameters | Same method name and parameters in a child class |
Happens within the same class (or subclasses) | Requires inheritance |
Resolved at compile time | Resolved at runtime |
Return type can differ if parameters differ | Return type must be the same or a subtype |
10. What is a constructor? What are its types?
A constructor is a special method that initialises an object when it's created. It has the same name as the class and no return type. Types include the default constructor (no parameters) and parameterised constructors. A class can have multiple constructors, which is called constructor overloading.
Intermediate OOPs Interview Questions
11. What is the difference between this and super?
this refers to the current object and is used to access its fields, methods or constructors. super refers to the parent class and is used to call the parent's constructor or methods, especially overridden ones.
12. What are access modifiers in Java?
Modifier | Accessible from |
|---|---|
private | Only within the same class |
default (no modifier) | Within the same package |
protected | Same package, plus subclasses in other packages |
public | Everywhere |
13. What does the static keyword mean?
A static member belongs to the class rather than to any object. Static variables are shared by all instances, and static methods can be called without creating an object, like Math.max(). Static methods can't directly access instance variables.
14. What does the final keyword do?
final variable: Its value can't be changed once assigned.
final method: It can't be overridden.
final class: It can't be extended, like the String class in Java.
15. Why doesn't Java support multiple inheritance with classes?
To avoid the diamond problem. If class C extends both A and B, and both define the same method, the compiler can't decide which one C should inherit. Java avoids this ambiguity by allowing a class to extend only one class, while letting it implement multiple interfaces.
16. What is the difference between association, aggregation and composition?
Association: A general relationship between two classes, like a Teacher and a Student.
Aggregation: A "has-a" relationship where the part can exist independently, like a Department and its Teachers.
Composition: A strong "has-a" relationship where the part can't exist without the whole, like a House and its Rooms.
17. Composition vs inheritance: which is better?
Inheritance models an "is-a" relationship (a Dog is an Animal). Composition models a "has-a" relationship (a Car has an Engine). Many developers prefer composition because it's more flexible and avoids tightly coupled class hierarchies. "Favour composition over inheritance" is a common design principle.
18. What are coupling and cohesion?
Coupling is how dependent classes are on each other, and lower is better. Cohesion is how focused a class is on a single purpose, and higher is better. Good OOP design aims for low coupling and high cohesion.
19. What are the SOLID principles?
S: Single Responsibility. A class should have one reason to change.
O: Open/Closed. Open for extension, closed for modification.
L: Liskov Substitution. Child classes should be usable wherever the parent is expected.
I: Interface Segregation. Prefer small, specific interfaces over large ones.
D: Dependency Inversion. Depend on abstractions, not concrete classes.
20. What is the difference between a shallow copy and a deep copy?
A shallow copy copies an object's fields, but nested objects are shared between the original and the copy. A deep copy creates independent copies of nested objects too, so changes to one don't affect the other.
Bonus: Explain OOP With a Real Example
Interviewers often ask you to apply OOP to a real system. Take a parking lot:
Classes: ParkingLot, ParkingSpot, Vehicle, Ticket
Inheritance: Car, Bike and Truck extend Vehicle
Encapsulation: Spot availability is private and changed only through methods like park() and leave()
Polymorphism: Each vehicle type calculates its own parking fee
Abstraction: A PaymentMethod interface with UPI and Card implementations
This kind of thinking is exactly what LLD and machine coding rounds test. Learn more in our System Design for Beginners guide.
How to Prepare for OOPs Interview Questions
Learn concepts with code, not just definitions. Write small examples for each pillar.
Prepare real-world examples for every concept, since interviewers almost always ask for one.
Practise LLD problems like a parking lot, library system or expense splitter.
Use OOP in your projects, so you can explain your class design in interviews. See 12 Resume Projects for Freshers That Stand Out in 2026.
Practise explaining out loud with DevsUnite Mock Interviews.
Frequently Asked Questions
What are the most important OOPs topics for interviews?
The four pillars, abstract class vs interface, overloading vs overriding, constructors, access modifiers, static and final, and why Java doesn't support multiple inheritance are the most commonly asked topics.
Which language should I use to answer OOPs questions?
Use the language you're most comfortable with. Java is very common in Indian fresher interviews because its OOP features are explicit, but C++ and Python are also accepted.
How do I explain polymorphism with a real-life example?
A person behaves differently as a student, a son or daughter, and a friend, which is one person in many forms. In code, a parent reference like Animal can point to a Dog or a Cat, and calling sound() produces different results.
Are OOPs questions asked in product-based company interviews?
Yes, especially in LLD and machine coding rounds, where you design classes for real systems. Service companies also ask OOPs concepts directly in technical rounds.
How long does it take to prepare OOPs for interviews?
Most freshers can cover interview-level OOPs in 1 to 2 weeks with daily practice. Applying concepts in small LLD problems and projects helps them stick.
Final Thoughts
OOPs questions are predictable, which makes them one of the easiest areas to prepare well. Understand each concept, practise it in code and keep a real-world example ready for every answer. Do that, and you'll handle both the basic questions and the tricky follow-ups confidently.
👉 Pair your OOPs prep with SQL: read Top 25 SQL Interview Questions for Freshers, and make sure your resume is ready with the DevsUnite ATS Resume Checker.
Practice
Practice this interview before the real one
Answer real interview questions out loud and get feedback on every answer from an AI interviewer.