# Object-Oriented Programming

> Explain and apply encapsulation, abstraction, inheritance and polymorphism with code, plus the OOP questions asked in almost every fresher interview. Free...

Canonical: https://www.internhack.in/roadmaps/tracks/dsa-placement/oop
Last updated: 2026-11-28

Explain and apply encapsulation, abstraction, inheritance and polymorphism with code, plus the OOP questions asked in almost every fresher interview.

Beginner · about 8 hours · difficulty 2/5

Learn first: [How Campus and Off-Campus Hiring Works](https://www.internhack.in/roadmaps/tracks/dsa-placement/placement-landscape)

OOP is the most asked theory topic in fresher interviews, especially at service companies. Expect definitions, small code examples and "what is the output" questions in your chosen language.

### The four pillars

- **Encapsulation**: bundle data with methods and hide it behind access modifiers (private, protected, public).
- **Abstraction**: expose what an object does, hide how. Abstract classes and interfaces.
- **Inheritance**: reuse and extend behaviour. Types: single, multilevel, hierarchical, multiple (via interfaces in Java), and the diamond problem (virtual inheritance in C++).
- **Polymorphism**: compile-time (method overloading, operator overloading in C++) and runtime (method overriding through virtual functions or dynamic dispatch).

### Frequently asked questions

- Class vs object, constructor types (default, parameterised, copy), destructors.
- Abstract class vs interface, and when to use each.
- Overloading vs overriding.
- static and final (Java), virtual functions and vtables (C++), this and super.
- Composition vs inheritance; "has-a" vs "is-a".
- Shallow vs deep copy.
- A short intro to **SOLID** principles and one or two design patterns (Singleton, Factory, Observer) for product-company rounds.

### Pitfalls

- Reciting textbook definitions without a code example. Always back each pillar with a 3 to 5 line snippet.
- Confusing abstraction with encapsulation.

You are ready to move on when you can explain all four pillars with your own code examples and answer overloading vs overriding with output prediction.

## Key concepts

- **Classes, objects, constructors**
- **Encapsulation and access modifiers**
- **Abstraction: abstract classes and interfaces**
- **Inheritance types and diamond problem**
- **Overloading vs overriding**
- **Virtual functions and dynamic dispatch**
- **Composition vs inheritance**
- **SOLID and common design patterns**

## Mini project

Build a small console Library Management system in your language with Book, Member and Librarian classes, an abstract LibraryItem, an interface for borrowable items, overloading and overriding examples, and a README mapping each OOP pillar to a line of code.

## Check yourself

What is the difference between an abstract class and an interface, and when would you choose each?

## Free resources

- [Oracle Java Tutorials: OOP concepts](https://docs.oracle.com/javase/tutorial/java/concepts/) (Oracle)
- [Refactoring.Guru: design patterns](https://refactoring.guru/design-patterns) (Refactoring.Guru)
- [LearnCpp.com](https://www.learncpp.com/) (LearnCpp)

Previous: [Verbal Ability and Communication](https://www.internhack.in/roadmaps/tracks/dsa-placement/verbal-ability) · Next: [DBMS Concepts](https://www.internhack.in/roadmaps/tracks/dsa-placement/dbms)

## More in CS Core Subjects for Interviews

- [Object-Oriented Programming](https://www.internhack.in/roadmaps/tracks/dsa-placement/oop)
- [DBMS Concepts](https://www.internhack.in/roadmaps/tracks/dsa-placement/dbms)
- [SQL for Interviews and OAs](https://www.internhack.in/roadmaps/tracks/dsa-placement/sql-interviews)
- [Operating Systems](https://www.internhack.in/roadmaps/tracks/dsa-placement/operating-systems)
- [Computer Networks](https://www.internhack.in/roadmaps/tracks/dsa-placement/computer-networks)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [DSA and Placement Prep Roadmap](https://www.internhack.in/roadmaps/tracks/dsa-placement)
