OOP Concepts Every Fresher Should Know
## OOP Concepts Every Fresher Should Know Object-Oriented Programming (OOP) organizes software around **objects**—entities that combine data and behavior. These are the core concepts: 1. **Class** A blueprint for creating objects. Example: `Car` can define properties like `brand`, `color`, and methods like `start()`. 2. **Object** A real instance of a class. Example: `myCar` is an object created from the `Car` class. 3. **Encapsulation** Bundling data and related methods together, while restricting direct access to internal details. Example: keeping `balance` private in a `BankAccount` and updating it only through `deposit()` or `withdraw()`. 4. **Abstraction** Showing only essential features and hiding complex implementation details. Example: you call `car.start()` without knowing how the engine starts internally. 5. **Inheritance** Creating a new class from an existing one to reuse and extend behavior. Example: `ElectricCar` inherits common features from `Car`. 6. **Polymorphism** The same method name can behave differently depending on the object. Example: `draw()` may render a circle differently from a rectangle. 7. **Constructor** A special method that runs when an object is created, usually to initialize its data. 8. **Method Overloading** Using the same method name with different parameters. Example: `add(int, int)` and `add(int, int, int)`. Note: support differs by language; Java supports it directly, Python typically uses alternatives. 9. **Method Overriding** A child class provides its own implementation of a method inherited from a parent class. 10. **Association, Aggregation, and Composition** These describe relationships between objects: * **Association:** A `Teacher` teaches a `Student`. * **Aggregation:** A `Department` has `Teachers`, but teachers can exist independently. * **Composition:** A `House` has `Rooms`; rooms are generally tied to that house. A simple Java example: ```java class Animal { void sound() { System.out.println("Some sound"); } } class Dog extends Animal { @Override void sound() { System.out.println("Bark"); } } public class Main { public static void main(String[] args) { Animal pet = new Dog(); // inheritance + polymorphism pet.sound(); // Bark } } ``` For interviews, be ready to explain each concept with one real-world example and one code example.