✅ OOP Interview Questions with Answers Part-4 🧠💻
31. What is SOLID in OOP?
SOLID is a set of 5 design principles for writing maintainable, scalable OOP code. It stands for:
S – Single Responsibility
O – Open/Closed
L – Liskov Substitution
I – Interface Segregation
D – Dependency Inversion
32. Explain each SOLID principle briefly:
• Single Responsibility – A class should do one thing only.
• Open/Closed – Classes should be open for extension, but closed for modification.
• Liskov Substitution – Subclasses should replace their parent classes without breaking functionality.
• Interface Segregation – Prefer small, specific interfaces over large ones.
• Dependency Inversion – Depend on abstractions, not concrete classes.
33. What is Liskov Substitution Principle?
If a class S is a subclass of class T, objects of type T should be replaceable with objects of type S without affecting the program.
Example: A Bird base class with a
34. What is Dependency Inversion Principle?
High-level modules should not depend on low-level modules. Both should depend on abstractions.
Example: A service class should depend on an interface, not a specific implementation.
35. What is object slicing?
Occurs when an object of a derived class is assigned to a base class variable — the extra properties of the derived class are "sliced off."
Example: C++ object slicing when passing by value.
36. What are getters and setters?
Special methods used to get and set values of private variables in a class.
They support encapsulation and validation.
37. What is a virtual function?
A function declared in the base class and overridden in the derived class, using the
38. What is early binding vs late binding?
• Early Binding (Static): Method call is resolved at compile time (e.g., method overloading).
• Late Binding (Dynamic): Method call is resolved at run-time (e.g., method overriding).
39. What is dynamic dispatch?
It’s the process where the method to be invoked is determined at runtime based on the object’s actual type — used in method overriding (late binding).
40. What is a pure virtual function?
A virtual function with no implementation in the base class — makes the class abstract.
Syntax (C++):
💬 Double Tap ♥️ for Part-5
31. What is SOLID in OOP?
SOLID is a set of 5 design principles for writing maintainable, scalable OOP code. It stands for:
S – Single Responsibility
O – Open/Closed
L – Liskov Substitution
I – Interface Segregation
D – Dependency Inversion
32. Explain each SOLID principle briefly:
• Single Responsibility – A class should do one thing only.
• Open/Closed – Classes should be open for extension, but closed for modification.
• Liskov Substitution – Subclasses should replace their parent classes without breaking functionality.
• Interface Segregation – Prefer small, specific interfaces over large ones.
• Dependency Inversion – Depend on abstractions, not concrete classes.
33. What is Liskov Substitution Principle?
If a class S is a subclass of class T, objects of type T should be replaceable with objects of type S without affecting the program.
Example: A Bird base class with a
fly() method may break if Penguin inherits it (Penguins can't fly). So, design must respect capabilities.34. What is Dependency Inversion Principle?
High-level modules should not depend on low-level modules. Both should depend on abstractions.
Example: A service class should depend on an interface, not a specific implementation.
35. What is object slicing?
Occurs when an object of a derived class is assigned to a base class variable — the extra properties of the derived class are "sliced off."
Example: C++ object slicing when passing by value.
36. What are getters and setters?
Special methods used to get and set values of private variables in a class.
They support encapsulation and validation.
def get_name(self): return self._name
def set_name(self, name): self._name = name
37. What is a virtual function?
A function declared in the base class and overridden in the derived class, using the
virtual keyword (in C++). Enables run-time polymorphism.38. What is early binding vs late binding?
• Early Binding (Static): Method call is resolved at compile time (e.g., method overloading).
• Late Binding (Dynamic): Method call is resolved at run-time (e.g., method overriding).
39. What is dynamic dispatch?
It’s the process where the method to be invoked is determined at runtime based on the object’s actual type — used in method overriding (late binding).
40. What is a pure virtual function?
A virtual function with no implementation in the base class — makes the class abstract.
Syntax (C++):
virtual void draw() = 0;
💬 Double Tap ♥️ for Part-5
❤5
𝗛𝗶𝗴𝗵 𝗗𝗲𝗺𝗮𝗻𝗱𝗶𝗻𝗴 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝗪𝗶𝘁𝗵 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗔𝘀𝘀𝗶𝘀𝘁𝗮𝗻𝗰𝗲😍
Learn from IIT faculty and industry experts.
IIT Roorkee DS & AI Program :- https://pdlink.in/4qHVFkI
IIT Patna AI & ML :- https://pdlink.in/4pBNxkV
IIM Mumbai DM & Analytics :- https://pdlink.in/4jvuHdE
IIM Rohtak Product Management:- https://pdlink.in/4aMtk8i
IIT Roorkee Agentic Systems:- https://pdlink.in/4aTKgdc
Upskill in today’s most in-demand tech domains and boost your career 🚀
Learn from IIT faculty and industry experts.
IIT Roorkee DS & AI Program :- https://pdlink.in/4qHVFkI
IIT Patna AI & ML :- https://pdlink.in/4pBNxkV
IIM Mumbai DM & Analytics :- https://pdlink.in/4jvuHdE
IIM Rohtak Product Management:- https://pdlink.in/4aMtk8i
IIT Roorkee Agentic Systems:- https://pdlink.in/4aTKgdc
Upskill in today’s most in-demand tech domains and boost your career 🚀
✅ OOP Interview Questions with Answers Part-5 🧠💻
41. What is multiple inheritance?
It means a class can inherit from more than one parent class.
✔ Supported in C++
✖ Not directly supported in Java (handled via interfaces)
42. What are mixins?
Mixins are a way to add reusable behavior to classes without using inheritance.
✔ Used in Python and JavaScript
✔ Promotes code reuse
43. What is the diamond problem in inheritance?
Occurs when two parent classes inherit from a common grandparent, and a child class inherits both.
❌ Creates ambiguity about which method to inherit.
44. How is the diamond problem solved in C++ or Java?
• C++: Uses virtual inheritance
• Java: Avoids it entirely using interfaces (no multiple class inheritance)
45. What are abstract data types in OOP?
ADTs define what operations can be done, not how.
Examples: Stack, Queue, List
✔ Implementation is hidden
✔ Promotes abstraction
46. What is a design pattern in OOP?
Reusable solution to a common software design problem.
✔ Templates for writing clean, maintainable code
47. What are some common OOP design patterns?
• Singleton – one instance
• Factory – object creation logic
• Observer – event-based updates
• Strategy – interchangeable behavior
• Adapter – interface compatibility
48. Interface vs Abstract Class (Real-world use)
• Interface – Contract; use when you want to define capability (e.g., Drivable)
• Abstract Class – Shared structure + behavior; base class for similar types (e.g., Vehicle)
49. What is garbage collection?
Automatic memory management – reclaims memory from unused objects.
✔ Java has a built-in GC
✔ Prevents memory leaks
50. Real-world use of OOP?
• Games – Objects for players, enemies
• Banking – Classes for accounts, transactions
• UI – Buttons, forms as objects
• E-commerce – Products, carts, users as objects
💬 Double Tap ❤️ For More!
41. What is multiple inheritance?
It means a class can inherit from more than one parent class.
✔ Supported in C++
✖ Not directly supported in Java (handled via interfaces)
42. What are mixins?
Mixins are a way to add reusable behavior to classes without using inheritance.
✔ Used in Python and JavaScript
✔ Promotes code reuse
43. What is the diamond problem in inheritance?
Occurs when two parent classes inherit from a common grandparent, and a child class inherits both.
❌ Creates ambiguity about which method to inherit.
44. How is the diamond problem solved in C++ or Java?
• C++: Uses virtual inheritance
• Java: Avoids it entirely using interfaces (no multiple class inheritance)
45. What are abstract data types in OOP?
ADTs define what operations can be done, not how.
Examples: Stack, Queue, List
✔ Implementation is hidden
✔ Promotes abstraction
46. What is a design pattern in OOP?
Reusable solution to a common software design problem.
✔ Templates for writing clean, maintainable code
47. What are some common OOP design patterns?
• Singleton – one instance
• Factory – object creation logic
• Observer – event-based updates
• Strategy – interchangeable behavior
• Adapter – interface compatibility
48. Interface vs Abstract Class (Real-world use)
• Interface – Contract; use when you want to define capability (e.g., Drivable)
• Abstract Class – Shared structure + behavior; base class for similar types (e.g., Vehicle)
49. What is garbage collection?
Automatic memory management – reclaims memory from unused objects.
✔ Java has a built-in GC
✔ Prevents memory leaks
50. Real-world use of OOP?
• Games – Objects for players, enemies
• Banking – Classes for accounts, transactions
• UI – Buttons, forms as objects
• E-commerce – Products, carts, users as objects
💬 Double Tap ❤️ For More!
❤4
📊 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 𝗙𝗥𝗘𝗘 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝘂𝗿𝘀𝗲😍
🚀Upgrade your skills with industry-relevant Data Analytics training at ZERO cost
✅ Beginner-friendly
✅ Certificate on completion
✅ High-demand skill in 2026
𝐋𝐢𝐧𝐤 👇:-
https://pdlink.in/497MMLw
📌 100% FREE – Limited seats available!
🚀Upgrade your skills with industry-relevant Data Analytics training at ZERO cost
✅ Beginner-friendly
✅ Certificate on completion
✅ High-demand skill in 2026
𝐋𝐢𝐧𝐤 👇:-
https://pdlink.in/497MMLw
📌 100% FREE – Limited seats available!
📊 SQL Interview Queries – Intermediate Level
━━━━━━━━━━━━━━
❓ Query 01: Find employees earning more than the average salary
SELECT *
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
❓ Query 02: Find department-wise employee count
SELECT department, COUNT(*) AS emp_count
FROM employees
GROUP BY department;
❓ Query 03: Find departments with average salary greater than 60,000
SELECT department
FROM employees
GROUP BY department
HAVING AVG(salary) > 60000;
❓ Query 04: Fetch employees who do not belong to any department
SELECT e.*
FROM employees e
LEFT JOIN departments d
ON e.department_id = d.department_id
WHERE d.department_id IS NULL;
❓ Query 05: Find second highest salary
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
❓ Query 06: Get highest salary in each department
SELECT department, MAX(salary)
FROM employees
GROUP BY department;
❓ Query 07: Fetch employees hired in the last 6 months
SELECT *
FROM employees
WHERE hire_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
❓ Query 08: Find duplicate email IDs
SELECT email, COUNT(*)
FROM employees
GROUP BY email
HAVING COUNT(*) > 1;
❓ Query 09: Rank employees by salary within each department
SELECT *,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank
FROM employees;
❓ Query 10: Fetch top 2 highest paid employees from each department
SELECT *
FROM (
SELECT *,
DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk
FROM employees
) t
WHERE rnk <= 2;
🔥 Show some love with a reaction ❤️
━━━━━━━━━━━━━━
❓ Query 01: Find employees earning more than the average salary
SELECT *
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
❓ Query 02: Find department-wise employee count
SELECT department, COUNT(*) AS emp_count
FROM employees
GROUP BY department;
❓ Query 03: Find departments with average salary greater than 60,000
SELECT department
FROM employees
GROUP BY department
HAVING AVG(salary) > 60000;
❓ Query 04: Fetch employees who do not belong to any department
SELECT e.*
FROM employees e
LEFT JOIN departments d
ON e.department_id = d.department_id
WHERE d.department_id IS NULL;
❓ Query 05: Find second highest salary
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
❓ Query 06: Get highest salary in each department
SELECT department, MAX(salary)
FROM employees
GROUP BY department;
❓ Query 07: Fetch employees hired in the last 6 months
SELECT *
FROM employees
WHERE hire_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
❓ Query 08: Find duplicate email IDs
SELECT email, COUNT(*)
FROM employees
GROUP BY email
HAVING COUNT(*) > 1;
❓ Query 09: Rank employees by salary within each department
SELECT *,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank
FROM employees;
❓ Query 10: Fetch top 2 highest paid employees from each department
SELECT *
FROM (
SELECT *,
DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk
FROM employees
) t
WHERE rnk <= 2;
🔥 Show some love with a reaction ❤️
❤5