Java OOP Concepts: Day 3 - Method Overloading, Inheritance & DI

🚀 Day 3 of my Java journey — OOP concepts! (Part 1) Today I explored Object Oriented Programming — the heart of Java! 🫀 ⚙️ Method Overloading ✅Same Class, Same method name, different parameters ✅ Example: add(int a, int b) ,add(int a, int b,int c) and add(double a, double b) ✅ Decided at compile time ✅Socho ek calculator hai — add button ek hi hai lekin tum 2 number bhi jod sakte ho, 3 number bhi! Same naam, alag parameter! 🔁 Method Overriding ✅ Child class redefines parent class method ✅ Same name, same parameters — different behaviour ✅ Decided at runtime — this is polymorphism! ✅Method Overriding — Child apna kaam khud karta hai ✅(Socho Papa kehte hain "khana khao" — matlab roti khao. Lekin beta kehta hai "khana khao" — matlab pizza khao! Same baat, alag matlab! ) ✅child apne papa ka kaam badal deta hai 🔑 this keyword ✅ Refers to the current object inside a class ✅ Used to avoid confusion between class variables and method parameters ✅this — "Main khud hoon(Intense variable,method and constructor )" 👨👩👦 super keyword ✅ Used to call parent class methods or constructor ✅ super() calls parent constructor ✅ super.methodName() calls parent method ✅ super — "Mere papa hain(parent Class)" 🧬 Inheritance ✅ Child class inherits properties and methods from parent class ✅ Single inheritance — one parent, one child ✅ Multiple inheritance via interfaces (Java does not allow multiple class inheritance directly) 💉 Dependency Injection(DI) ✅ Instead of creating objects inside a class, we pass them from outside ✅ Makes code flexible, testable and clean ✅ Used heavily in Spring Boot (next goal!) Socho tumhara ek Car hai. Car ko Engine chahiye. ✅Bina DI: Car khud engine banati hai andar — agar engine badlani ho toh poori car todna padega! ✅DI ke saath: Engine bahar se car mein daali jaati hai — engine badlo, car wahi rehti hai! ✅Galat tarika — tightly coupled ✅cheez bahar se do, andar mat banao OOP is not finished yet — Day 4 will cover more! 🔥 Day 1 ✅ | Day 2 ✅ | Day 3 ✅ | Day 4 coming... If you are on a similar Java journey, connect with me! 🙏 #Java #JavaDeveloper #OOP #ObjectOrientedProgramming #Inheritance #Polymorphism #DependencyInjection #100DaysOfCode #BackendDevelopment #TechCareer

To view or add a comment, sign in

Explore content categories