50+ Interview Questions on Object Oriented Programming with Answers (2025)
- Gunashree RS
- 22 hours ago
- 13 min read
Preparing for a programming interview can feel overwhelming, especially when it comes to Object-Oriented Programming concepts. As someone who wants to help you succeed, I've compiled over 50 actual interview questions on object-oriented programming that real companies ask, complete with detailed answers and explanations.
This isn't just another list of concepts - these are genuine questions I've encountered in interviews at major tech companies, along with the answers that will help you demonstrate your expertise and land that job.

Basic OOP Concepts Interview Questions (Questions 1-15)
Question 1: What is Object-Oriented Programming?
Answer: Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around data (objects) rather than functions and logic. It's based on four main principles: Encapsulation, Inheritance, Polymorphism, and Abstraction. OOP helps create modular, reusable, and maintainable code by modeling real-world entities as objects that contain both data (attributes) and methods (functions).
Question 2: What's the difference between a class and an object?
Answer:
Class: A blueprint or template that defines the structure and behavior of objects. It doesn't consume memory until instantiated.
Object: An instance of a class that exists in memory with actual values for its attributes.
Example: If Car is a class, then myCar = new Car("Toyota", "Red") creates an object with specific values.
Question 3: What are the four pillars of OOP?
Answer:
Encapsulation: Bundling data and methods together while hiding internal details
Inheritance: Creating new classes based on existing classes
Polymorphism: One interface, multiple implementations
Abstraction: Hiding complex implementation details while showing only essential features
Question 4: Explain encapsulation with an example.
Answer: Encapsulation means keeping data and methods that work on that data within one unit (class) and controlling access to them.
public class BankAccount {
private double balance; // Private data
public void deposit(double amount) { // Public method
if(amount > 0) {
balance += amount;
}
}
public double getBalance() { // Controlled access
return balance;
}
}
The balance is private and can only be modified through controlled methods.
Question 5: What are access modifiers?
Answer:
Public: Accessible from anywhere
Private: Only accessible within the same class
Protected: Accessible within the class and its subclasses
Package/Default: Accessible within the same package
Question 6: What is inheritance?
Answer: Inheritance allows a class to inherit properties and methods from another class. The inheriting class is called a child/derived class, and the inherited class is called a parent/base class.
class Animal {
protected String name;
public void eat() { System.out.println("Animal eats"); }
}
class Dog extends Animal {
public void bark() { System.out.println("Dog barks"); }
}
Question 7: What are the types of inheritance?
Answer:
Single Inheritance: One child inherits from one parent
Multiple Inheritance: One child inherits from multiple parents (not supported in Java)
Multilevel Inheritance: Chain inheritance (A→B→C)
Hierarchical Inheritance: Multiple children inherit from one parent
Hybrid Inheritance: Combination of multiple types
Question 8: What is polymorphism?
Answer: Polymorphism allows objects of different types to be treated as instances of the same type through a common interface. There are two types:
Runtime Polymorphism (Method Overriding):
class Animal {
public void makeSound() { System.out.println("Animal makes sound"); }
}
class Dog extends Animal {
public void makeSound() { System.out.println("Dog barks"); }
}
Compile-time Polymorphism (Method Overloading):
class Calculator {
public int add(int a, int b) { return a + b; }
public double add(double a, double b) { return a + b; }
}
Question 9: What's the difference between method overriding and overloading?
Answer:
Method Overriding: Redefining a parent class method in a child class (runtime polymorphism)
Method Overloading: Multiple methods with the same name but different parameters (compile-time polymorphism)
Question 10: What is abstraction?
Answer: Abstraction hides the complex implementation details and shows only the essential features of an object. It's achieved through abstract classes and interfaces.
abstract class Shape {
abstract double calculateArea(); // Abstract method
public void display() { // Concrete method
System.out.println("This is a shape");
}
}
Question 11: What's the difference between abstract classes and interfaces?
Answer:
Abstract Classes | Interfaces |
Can have concrete methods | All methods are abstract (before Java 8) |
Can have constructors | Cannot have constructors |
Can have instance variables | Only constants (public static final) |
Single inheritance | Multiple inheritance |
Can have any access modifier | Public by default |
Question 12: What is a constructor?
Answer: A constructor is a special method that's automatically called when an object is created. It initializes the object's state.
public class Person {
private String name;
// Default constructor
public Person() {
this.name = "Unknown";
}
// Parameterized constructor
public Person(String name) {
this.name = name;
}
}
Question 13: What are the types of constructors?
Answer:
Default Constructor: No parameters, provided by the compiler if no constructor is defined
Parameterized Constructor: Takes parameters to initialize an object with specific values
Copy Constructor: Creates a new object by copying another object (not available in Java)
Question 14: What is constructor overloading?
Answer: Having multiple constructors with different parameter lists in the same class.
public class Rectangle {
private int length, width;
public Rectangle() { length = width = 1; }
public Rectangle(int side) { length = width = side; }
public Rectangle(int l, int w) { length = l; width = w; }
}
Question 15: What is the this keyword?
Answer: this refers to the current object instance. It's used to:
Differentiate between instance variables and parameters
Call other constructors in the same class
Pass the current object as a parameter
public class Student {
private String name;
public void setName(String name) {
this.name = name; // this.name refers to instance variable
}
}
Intermediate OOP Interview Questions (Questions 16-35)
Question 16: What is the super keyword?
Answer: super refers to the immediate parent class object. It's used to:
Call parent class methods
Access parent class variables
Invoke parent class constructors
class Animal {
protected String name = "Animal";
public void display() { System.out.println("Animal display"); }
}
class Dog extends Animal {
private String name = "Dog";
public void show() {
System.out.println(super.name); // Prints "Animal"
super.display(); // Calls parent method
}
}
Question 17: What is method chaining?
Answer: Method chaining allows calling multiple methods on the same object in a single statement by returning this from each method.
public class StringBuilder {
public StringBuilder append(String str) {
// append logic
return this;
}
}
// Usage: sb.append("Hello").append(" ").append("World");
Question 18: What is composition?
Answer: Composition is a "has-a" relationship where one class contains objects of other classes as instance variables.
class Engine {
public void start() { System.out.println("Engine started"); }
}
class Car {
private Engine engine; // Car HAS-A Engine
public Car() {
engine = new Engine();
}
public void startCar() {
engine.start();
}
}
Question 19: What's the difference between composition and inheritance?
Answer:
Inheritance (is-a): Dog is-a Animal
Composition (has-a): Car has-a Engine
Composition is often preferred because it provides better flexibility and avoids deep inheritance hierarchies.
Question 20: What is aggregation?
Answer: Aggregation is a weak "has-a" relationship where the contained objects can exist independently of the container.
class Department {
private List<Employee> employees;
// Employees can exist without a Department
}
Question 21: What are static methods and variables?
Answer: Static members belong to the class rather than any instance:
Static variables: Shared among all instances of the class
Static methods: Can be called without creating an object
public class Counter {
private static int count = 0; // Static variable
public static void increment() { // Static method
count++;
}
public static int getCount() {
return count;
}
}
// Usage: Counter.increment(); // No object needed
Question 22: Can you override static methods?
Answer: No, static methods cannot be overridden because they belong to the class, not the object. However, you can hide them by declaring a static method with the same signature in the subclass.
Question 23: What is a final keyword?
Answer: The final keyword can be used with:
Variables: Make them constants
Methods: Prevents overriding
Classes: Prevent inheritance
final class Constants {
public static final int MAX_SIZE = 100;
public final void display() {
System.out.println("Cannot be overridden");
}
}
Question 24: What are inner classes?
Answer: Inner classes are classes defined within another class. Types include:
Non-static inner class: Has access to outer class instance
Static nested class: Independent of the outer class instance
Local class: Defined within a method
Anonymous class: Class without a name
public class Outer {
private int x = 10;
class Inner { // Non-static inner class
public void display() {
System.out.println(x); // Can access outer class members
}
}
}
Question 25: What is an anonymous class?
Answer: An anonymous class is a local class without a name, often used for implementing interfaces or extending classes inline.
Runnable r = new Runnable() {
public void run() {
System.out.println("Running in anonymous class");
}
};
Question 26: What is the difference between == and equals()?
Answer:
==: Compares references (addresses) for objects, values for primitives
equals(): Compares the actual content of objects (if properly overridden)
String s1 = new String("Hello");
String s2 = new String("Hello");
System.out.println(s1 == s2); // false (different objects)
System.out.println(s1.equals(s2)); // true (same content)
Question 27: What is the hashCode() method?
Answer: hashCode() returns an integer hash code for the object, used in hash-based collections like HashMap. If two objects are equal (according to equals()), they must have the same hash code.
Question 28: What is the toString() method?
Answer: toString() returns a string representation of the object. It's automatically called when printing objects.
public class Person {
private String name;
@Override
public String toString() {
return "Person{name='" + name + "'}";
}
}
Question 29: What are packages?
Answer: Packages are namespaces that organize related classes and interfaces. They help avoid naming conflicts and control access.
package com.company.utils;
import java.util.ArrayList;
public class Helper {
// class implementation
}
Question 30: What is the difference between public, protected, default, and private?
Answer:
public: Accessible everywhere
protected: Accessible within the package and subclasses
default: Accessible within the package only
private: Accessible within the class only
Question 31: What are getters and setters?
Answer: Getters and setters are methods used to access and modify private variables, providing controlled access to class fields.
public class Person {
private String name;
public String getName() { // Getter
return name;
}
public void setName(String name) { // Setter
if(name != null && !name.isEmpty()) {
this.name = name;
}
}
}
Question 32: What is exception handling in OOP?
Answer: Exception handling manages runtime errors using try-catch blocks, allowing programs to continue execution gracefully.
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
} finally {
System.out.println("This always executes");
}
Question 33: What is multiple inheritance, and why isn't it supported in Java?
Answer: Multiple inheritance allows a class to inherit from multiple parent classes. Java doesn't support it for classes because of the "Diamond Problem" - ambiguity when multiple parents have methods with the same signature. However, Java supports multiple inheritance through interfaces.
Question 34: What is interface segregation?
Answer: The Interface Segregation Principle states that clients shouldn't be forced to depend on interfaces they don't use. It's better to have multiple specific interfaces than one general interface.
// Bad
interface Worker {
void work();
void eat();
}
// Good
interface Workable {
void work();
}
interface Eatable {
void eat();
}
Question 35: What is dependency injection?
Answer: Dependency injection is a design pattern where dependencies are provided to a class rather than the class creating them itself, promoting loose coupling.
public class Car {
private Engine engine;
// Constructor injection
public Car(Engine engine) {
this.engine = engine;
}
}
Advanced OOP Interview Questions (Questions 36-50+)
Question 36: What is the Singleton pattern?
Answer: Singleton ensures only one instance of a class exists and provides global access to it.
public class Singleton {
private static Singleton instance;
private Singleton() {} // Private constructor
public static synchronized Singleton getInstance() {
if(instance == null) {
instance = new Singleton();
}
return instance;
}
}
Question 37: What is the Factory pattern?
Answer: The Factory pattern creates objects without specifying their exact classes, using a common interface.
interface Animal {
void makeSound();
}
class AnimalFactory {
public static Animal createAnimal(String type) {
switch(type) {
case "dog": return new Dog();
case "cat": return new Cat();
default: throw new IllegalArgumentException("Unknown animal");
}
}
}
Question 38: What is the Observer pattern?
Answer: The Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all dependents are notified.
interface Observer {
void update(String message);
}
class Subject {
private List<Observer> observers = new ArrayList<>();
public void addObserver(Observer observer) {
observers.add(observer);
}
public void notifyObservers(String message) {
for(Observer observer : observers) {
observer.update(message);
}
}
}
Question 39: What are the SOLID principles?
Answer: SOLID is an acronym for five design principles:
Single Responsibility Principle
Open/Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Question 40: What is the difference between shallow copy and deep copy?
Answer:
Shallow Copy: Copies object references, not the actual objects
Deep Copy: Creates new objects for all referenced objects
// Shallow copy
Person p1 = new Person("John");
Person p2 = p1; // Same object reference
// Deep copy
Person p3 = new Person(p1.getName()); // New object
Question 41: What is reflection in Java?
Answer: Reflection allows examining and modifying classes, methods, and fields at runtime.
Class<?> clazz = Person.class;
Method[] methods = clazz.getDeclaredMethods();
for(Method method : methods) {
System.out.println(method.getName());
}
Question 42: What is serialization?
Answer: Serialization converts objects into byte streams for storage or transmission. The object must implement the Serializable interface.
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
}
Question 43: What are generics?
public class Box<T> {
private T content;
public void setContent(T content) {
this.content = content;
}
public T getContent() {
return content;
}
}
Question 44: What is the difference between ArrayList and LinkedList?
Answer:
ArrayList: Uses dynamic arrays, fast random access, slower insertion/deletion
LinkedList: Uses doubly-linked lists, slower access, faster insertion/deletion
Question 45: What is multithreading in OOP?
Answer: Multithreading allows concurrent execution of multiple threads within a program.
class MyThread extends Thread {
public void run() {
System.out.println("Thread running: " + Thread.currentThread().getName());
}
}
// Usage
MyThread thread = new MyThread()
thread.start();
Question 46: What is synchronization?
Answer: Synchronization prevents multiple threads from accessing shared resources simultaneously, avoiding data corruption.
public synchronized void incrementCounter() {
counter++;
}
Question 47: What is the volatile keyword?
Answer: volatile ensures that changes to a variable are immediately visible to all threads, preventing caching issues in multithreaded environments.
Question 48: What is a deadlock?
Answer: A Deadlock occurs when two or more threads are blocked forever, waiting for each other to release resources.
Question 49: What is the difference between a process and a thread?
Answer:
Process: An Independent execution unit with its own memory space
Thread: Lightweight execution unit that shares memory with other threads in the same process
Question 50: What are lambda expressions?
Answer: Lambda expressions provide a concise way to represent anonymous functions, especially useful with functional interfaces.
// Traditional approach
Comparator<String> comp = new Comparator<String>() {
public int compare(String a, String b) {
return a.compareTo(b);
}
};
// Lambda expression
Comparator<String> comp = (a, b) -> a.compareTo(b);
Question 51: What is a method reference?
Answer: Method reference is a shorthand for lambda expressions that call existing methods.
// Lambda
list.forEach(x -> System.out.println(x));
// Method reference
list.forEach(System.out::println);
Question 52: What is the Stream API?
Answer: Stream API provides functional programming features for processing collections of data.
List<String> names = Arrays.asList("John", "Jane", "Bob");
names.stream()
.filter(name -> name.startsWith("J"))
.map(String::toUpperCase)
.forEach(System.out::println);
Frequently Asked Questions
How many OOP questions should I prepare for an interview?
You should be comfortable with at least 30-40 fundamental questions covering the four pillars of OOP, basic concepts, and some advanced topics. The questions in this guide cover everything you need.
Which OOP concepts are most important for interviews?
The four pillars (encapsulation, inheritance, polymorphism, and abstraction) are absolutely crucial. Also, focus on constructors, access modifiers, static vs instance members, and basic design patterns.
Should I learn design patterns for OOP interviews?
Yes, at least know Singleton, Factory, and Observer patterns. These frequently come up in interviews and demonstrate advanced OOP understanding.
How do I practice coding OOP questions?
Start with simple class design problems, then move to system design questions like designing a library management system, banking application, or e-commerce platform using OOP principles.
What's the best way to explain OOP concepts during interviews?
Always use real-world examples and analogies. For instance, explain encapsulation using a bank account example, or inheritance using animal hierarchies. Code examples help too.
Do I need to know language-specific details?
Yes, know the specifics of your target language. For Java, understand access modifiers, the final keyword, and static members. For Python, know about private naming conventions and multiple inheritance.
How detailed should my answers be?
Start with a concise definition, then provide an example. Be ready to go deeper if asked. Practice explaining complex concepts in simple terms.
What coding problems should I expect?
Common problems include designing class hierarchies, implementing design patterns, creating systems with proper encapsulation, and demonstrating polymorphism through practical examples.
Conclusion
These 50+ interview questions on object-oriented programming represent real scenarios you'll encounter in technical interviews. The key to success isn't memorizing answers, but understanding the underlying concepts deeply enough to explain them clearly and apply them to solve problems.
Remember that interviewers want to see your thought process, not just your knowledge of definitions. Practice explaining these concepts out loud, work through the coding examples, and be ready to discuss trade-offs between different approaches.
The time you invest in mastering these OOP concepts will pay dividends not just in interviews, but throughout your programming career. Object-oriented principles form the foundation of most modern software development, making this knowledge invaluable for any serious programmer.
Take your time to understand each concept, practice the code examples, and think about how these principles apply to real-world software development. With solid preparation using these questions and answers, you'll be well-equipped to demonstrate your OOP expertise and land your dream programming job.
Key Takeaways: Interview questions on object-oriented programming
• Master the four pillars of OOP with practical examples and be ready to code implementations during interviews
• Understand the difference between method overriding vs overloading, composition vs inheritance, and abstract classes vs interfaces
• Practice explaining complex concepts using simple real-world analogies that non-technical people can understand
• Know at least 3-5 design patterns (Singleton, Factory, Observer) with actual code implementations
• Be prepared for system design questions that require applying OOP principles to real-world scenarios
• Understand language-specific features like Java's access modifiers, static keyword, and exception handling
• Practice coding class hierarchies and demonstrating polymorphism through practical examples
• Know the SOLID principles and how they apply to writing maintainable object-oriented code
• Understand multithreading concepts including synchronization, deadlock, and thread safety in OOP contexts
• Be comfortable discussing modern features like generics, lambda expressions, and streams in your target language
• Practice explaining the benefits and drawbacks of different OOP approaches and when to use each
• Prepare for follow-up questions that dive deeper into your reasoning and understanding of trade-offs
Sources
Oracle Java OOP Tutorial - Official Java documentation covering fundamental OOP concepts
GeeksforGeeks OOP Interview Questions - Comprehensive collection of technical interview questions with examples
InterviewBit OOP Questions - 40+ interview questions with detailed explanations and code samples
LeetCode System Design - Real interview questions from major tech companies
Cracking the Coding Interview by Gayle McDowell - Industry standard interview preparation resource
Head First Design Patterns - A Comprehensive guide to OOP design patterns with practical examples
Clean Code by Robert Martin - Best practices for object-oriented programming and design
Effective Java by Joshua Bloch - Advanced Java programming techniques and OOP principles
Python Object-Oriented Programming by Steven Lott - Python-specific OOP concepts and interview preparation