Object-Oriented Programming
OOP concepts, relationships, design principles, and common interview questions.
- Introduction to OOP — Why OOP emerged, where it is useful today, and how it relates to functional programming.
- Class & Object — The foundation of object-oriented modeling: classes, objects, references, identity and pass-by-value.
- Constructors — Why constructors exist, how they protect valid objects, how this() and super() chain, and the order Java initialises an object in.
- this & super — What this and super refer to, their common uses, and how super calls differ from normal dynamic dispatch.
- Static Keyword — Static variables, methods, blocks and nested classes, static vs instance members, and why static methods are hidden rather than overridden.
- Access Modifiers — Public, protected, package-private and private access in Java, including the protected and private rules interviewers like to probe.
- Object Lifecycle & Memory — Object creation, references, heap and stack, reachability-based garbage collection, and how Java programs still leak memory.
- Encapsulation — Data hiding, invariants, getters and setters, defensive copies, and why encapsulation matters.
- Abstraction — Abstract classes, interfaces, real examples, leaky abstractions, and abstraction vs encapsulation.
- Polymorphism — Runtime polymorphism through overriding and dynamic dispatch, compile-time overloading, and what is not polymorphic in Java.
- Inheritance — Types of inheritance, extends, what is and is not inherited, the diamond problem, and the fragile base class risk.
- Relationships Between Classes — Dependency, association, aggregation, composition and inheritance, and how each shows up in Java code.
- Composition vs Inheritance — Pros, cons, when to use each, and backend examples.
- Interface vs Abstract Class — Differences, use cases, Java 8+ default methods, and backend examples.
- Method Overloading vs Overriding — Differences, rules, and interview questions.
- SOLID Principles — Five object-oriented design principles that make code easier to change.
- Single Responsibility Principle — A class should have one clear reason to change.
- Open/Closed Principle — Code should be open for extension but closed for modification.
- Liskov Substitution Principle — Subtypes should be safely usable wherever the parent type is expected.
- Interface Segregation Principle — Prefer small focused interfaces over large forced contracts.
- Dependency Inversion Principle — High-level code should depend on abstractions, not concrete low-level classes.
- Design Patterns — Singleton, Factory, Builder, Strategy, Adapter, Decorator and Observer, with backend examples.
- Common OOP Interview Questions — Frequently asked OOP interview questions with short, Java-accurate answers.