CS Fundamentals · Fresher-relevant
OOPs interview questions on encapsulation, inheritance, polymorphism, abstraction, and design patterns — a core topic at every service company.
What are the four pillars of object-oriented programming?
Tip: Encapsulation (bundle data with methods, hide internals), Abstraction (expose what, hide how), Inheritance (reuse via is-a relationships), and Polymorphism (one interface, many implementations). Give a one-line real-world example of each rather than reciting definitions.
What is the difference between method overloading and overriding?
Tip: Overloading = same method name, different parameter lists, resolved at compile time (static polymorphism). Overriding = subclass redefines a superclass method with the same signature, resolved at runtime (dynamic dispatch). Overriding requires inheritance; overloading does not.
Explain composition vs inheritance. Which do you prefer?
Tip: Inheritance models is-a and couples a subclass to its parent's implementation. Composition models has-a by holding other objects and delegating. Prefer composition for flexibility and to avoid fragile deep hierarchies — "favour composition over inheritance".
What are the SOLID principles?
Tip: Single Responsibility (one reason to change), Open/Closed (open to extension, closed to modification), Liskov Substitution (subtypes must be usable as their base), Interface Segregation (small focused interfaces), Dependency Inversion (depend on abstractions, not concretions). They reduce coupling and ease change.
What is abstraction vs encapsulation? They sound similar.
Tip: Abstraction is a design concern — hiding complexity behind a simple interface (what an object does). Encapsulation is an implementation concern — restricting direct access to internal state via access modifiers (how it protects data). One hides complexity, the other hides data.
What design patterns have you used? Explain one.
Tip: Group them: creational (Singleton, Factory, Builder), structural (Adapter, Decorator, Facade), behavioural (Observer, Strategy, Command). Explain one with a concrete use — e.g. Strategy to swap payment processors at runtime without changing the checkout code.
What is polymorphism and how is it achieved at runtime?
Tip: Polymorphism lets a base reference invoke the correct subclass implementation. At runtime it works via a virtual method table (vtable): the object carries a pointer to its type's method table, so the call dispatches to the actual type's override, not the reference type's.
Why is the Singleton pattern often criticised?
Tip: Singletons introduce global mutable state, hidden dependencies, and tight coupling that make unit testing and concurrency hard. If you need one instance, prefer injecting a single instance via a DI container rather than a static getInstance(). Ensure thread safety if you must implement one.
InterviewEra generates role-specific questions using your actual projects and skills. Get scored feedback on technical depth, clarity, and structure — free to start.