🚀 Day 53 / 180 — Java Full Stack Learning Topic: Rules of Method Overriding 🔹 1️⃣ Method Signature Must Be Same Signature = method name + parameter list (type, order, number) Return type not part of signature. ✅ Example: class Parent { void show(int a) { } } class Child extends Parent { void show(int a) { } // ✅ overriding } 🔹 2️⃣ Return Type Rule — Covariant Return Type Before Java 1.5 → return type must be exact same. After Java 1.5 → allowed to return subclass type (if return type is a class, not primitive). ✅ Example: class Animal {} class Dog extends Animal {} class Parent { Animal getAnimal() { return new Animal(); } } class Child extends Parent { Dog getAnimal() { return new Dog(); } // ✅ covariant return } ❌ Primitive types must match exactly. 🔹 3️⃣ Access Modifier Rule Can widen access, but cannot reduce it. Parent Modifier Allowed in Child public public only protected protected, public default (package) default, protected, public private cannot override ✅ Example: class Parent { protected void display() {} } class Child extends Parent { public void display() {} // ✅ wider } 🔹 4️⃣ Private Methods Cannot Be Overridden Private = not inherited. Same name in child = new method, not override. ✅ Example: class Parent { private void show() { System.out.println("Parent"); } } class Child extends Parent { void show() { System.out.println("Child"); } // new method } ➡️ @Override not allowed here. 🔹 5️⃣ Static Methods → Method Hiding, Not Overriding Static methods belong to class, not object. Both can have same signature, but method hiding occurs. ✅ Example: class Parent { static void show() { System.out.println("Parent"); } } class Child extends Parent { static void show() { System.out.println("Child"); } // Hiding } 🔹 6️⃣ Final Methods Cannot Be Overridden final → cannot change or override in subclass. final class → cannot be inherited. ✅ Example: class Parent { final void run() { System.out.println("Parent run"); } } class Child extends Parent { // void run() {} ❌ Error } 🔹 7️⃣ Exception Handling in Overriding If parent throws checked exception: Child may throw same or subclass exception. Or throw none. If parent doesn’t throw checked exception → child cannot throw new checked exception. ✅ Example: class Parent { void show() throws Exception {} } class Child extends Parent { void show() throws IOException {} // ✅ subclass } ❌ Invalid Example: class Parent { void show() {} } class Child extends Parent { void show() throws IOException {} // ❌ compile-time error } 🔹 8️⃣ Abstract Method Overriding Abstract parent → child must implement all abstract methods. Abstract subclass of normal class → can make a concrete method abstract again. ✅ Example: class Normal { void display() { System.out.println("Normal display"); } } abstract class AbstractChild extends Normal { abstract void display(); // ✅ allowed } #Java#JavaProgramming#JavaDeveloper
"Java Full Stack Learning: Rules of Method Overriding"
More Relevant Posts
-
I recently started learning Java. And learning it after Python feels like learning to drive manual after automatic 😅 Here's my roadmap and what I'm discovering at each stage: 1️⃣ Basic (Week 1-2) - Syntax & Variables, Data Types, Control Flow, Loops, Arrays. - I'm realising Java's strictness teaches discipline Python let me skip. - 𝘍𝘪𝘳𝘴𝘵 𝘴𝘵𝘳𝘶𝘨𝘨𝘭𝘦: Remembering semicolons and type declarations everywhere. 2️⃣ OOPs (Week 3-4) - Classes & Objects, Inheritance, Polymorphism, Abstraction, Encapsulation. - Everything MUST be in a class - no shortcuts. - Forces you to think in objects from day one. - Understanding why Java is called "𝘱𝘶𝘳𝘦𝘭𝘺 𝘰𝘣𝘫𝘦𝘤𝘵-𝘰𝘳𝘪𝘦𝘯𝘵𝘦𝘥" compared to Python's hybrid approach. 3️⃣ Collections (Week 5) - List, Set, Map, Generics, Iterators. - ArrayList vs LinkedList isn't just preference - it's understanding when fast access beats fast insertion. 4️⃣ Exception Handling (Week 6) - Try-Catch, Throw & Throws, Custom Exceptions. - Learning when to catch exceptions vs when to throw them. - Exception handling separates amateur code from production-ready code. 5️⃣ File I/O (Week 7) - FileReader/Writer, BufferedReader/Writer, Serialization. - Reading and writing files efficiently. Buffered I/O is significantly faster than basic I/O - matters at scale. - Serialization lets you save object states - crucial for real applications. 6️⃣ Multithreading (Week 8-9) - Thread & Runnable, Synchronization, Executors. - Mind-bending but powerful. Making programs do multiple things simultaneously without breaking. - 𝘏𝘢𝘳𝘥𝘦𝘴𝘵 𝘱𝘢𝘳𝘵 𝘴𝘰 𝘧𝘢𝘳: Understanding thread safety and avoiding race conditions. 7️⃣ Java 8+ (Week 10) - Lambda, Stream API, Functional Interfaces, Date & Time API. - Modern Java feels cleaner. Lambdas reduce boilerplate, Streams make data processing elegant. - This is where Java catches up to modern programming paradigms. 8️⃣ JDBC (Week 11) - Connection, Statements, Transactions. - Connecting Java to databases. Every backend application needs this. - Learning to write clean database code that doesn't leak connections or crash under load. 9️⃣ Frameworks (Week 12-14) - Spring Boot, Hibernate, Maven/Gradle. - The real world runs on frameworks. Spring Boot powers enterprise applications globally. - This is where Java's verbose nature pays off - frameworks handle the boilerplate. 🔟 Web Dev (Week 15-16) - Servlets & JSP, REST API, Spring MVC. - Building actual web applications. RESTful APIs are how modern apps communicate. - 𝘎𝘰𝘢𝘭: Build a complete backend system that can handle real traffic. 😥 Why am I learning Java when Python dominates AI? Enterprise systems run on Java. Python gets you started, Java gets you scale. Where are you in your Java journey? What's tripping you up? 👇 Follow Arijit Ghosh for daily shares and my learning journeys #Java #roadmap #programming
To view or add a comment, sign in
-
-
Oops in JAVA 🔥 Repost and help others. ✨In Java, the "Oops" concept refers to Object-Oriented Programming, a paradigm where programs are organized around objects that interact with each other. ✨Key principles include encapsulation, which hides internal implementation details; ✨ inheritance, allowing classes to inherit attributes and methods from others; ✨ polymorphism, enabling objects to be treated as instances of their parent class; and abstraction, where complex systems are represented by simplified models. ✨Java, being an OOP language, implements these principles through classes and objects, facilitating modular and maintainable code. 𝗙𝗥𝗘𝗘 (𝗚𝗼𝗼𝗴𝗹𝗲) 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘆𝗼𝘂 𝘄𝗶𝗹𝗹 𝗿𝗲𝗴𝗿𝗲𝘁 𝗻𝗼𝘁 𝘁𝗮𝗸𝗶𝗻𝗴 𝗶𝗻 𝟮𝟬𝟮𝟱. 1. Google Data Analytics: → https://lnkd.in/g83cqeGh 2. Google Project Management: → https://lnkd.in/gpZ6cuk5 3. Foundations of Project Management: → https://lnkd.in/gNKpDduP 4. Google Introduction to Generative AI: → https://lnkd.in/g-J5sUGf 5. Google Cybersecurity: → https://lnkd.in/gJ4CYYgf 6. Google UX Design: → https://lnkd.in/g8uZwNqN 7. Google Digital Marketing & E-commerce: → https://lnkd.in/gZrc4Fnv 8. Google IT Support: → https://lnkd.in/gEaB6FzQ 9. Web Applications for Everybody Specialization: → https://lnkd.in/gshfFzBk 10. Get Started with Python: → https://lnkd.in/g8GGCQgE 11. Learn Python Basics for Data Analysis: → https://lnkd.in/gumuN6Mi 12. Create your own Python objects → https://lnkd.in/gsmZxzar 13. Data Analysis with R Programming: → https://lnkd.in/gk2Ny2M3 14. IBM Full Stack Software Developer Professional Certificate: → https://lnkd.in/gsJhz6sQ 15. Introduction to Web Development with HTML, CSS, JavaScript: → https://lnkd.in/gnHdhXm2 16. IBM Front-End Developer Professional Certificate: → https://lnkd.in/g84pmt2z 17. IBM Back-End Development Certificate: → https://lnkd.in/gi5TDNRK 18. IBM Python for Data Science, AI & Development: → https://lnkd.in/gk2Ny2M3 19. Introduction to Data Science → https://lnkd.in/g83cqeGh 𝐇𝐞𝐫𝐞 𝐚𝐫𝐞 𝐭𝐡𝐞 𝐭𝐨𝐩 10 𝐅𝐑𝐄𝐄 𝐀𝐈 𝐜𝐨𝐮𝐫𝐬𝐞𝐬 𝐭𝐨 𝐠𝐞𝐭 𝐲𝐨𝐮 𝐦𝐚𝐬𝐬𝐢𝐯𝐞𝐥𝐲 𝐚𝐡𝐞𝐚𝐝: 1. AI Agent Developer: https://lnkd.in/gm4RyBzv 2. Prompt Engineering: https://lnkd.in/gVKwnD62 3. Machine Learning: https://lnkd.in/gvZVRjQU 4. Deep Learning: https://lnkd.in/gnHRrqBP 5. Gen AI for Automation: https://lnkd.in/gurhbX5S Follow for more ✨
To view or add a comment, sign in
-
🚀 Java Learning Series — Day 3 Topic: Exception and Its Types ☕ When we write a program, things don’t always go as planned Right??? Java gives us "Exceptions" — Special ways to handle those unexpected Bugs so our code doesn’t crash suddenly. ------------------------------------- 💡 Definition: An Exception is like a signal that something went wrong during program execution. Instead of stopping everything, Java lets us catch and handle it. ------------------------------------- ✅ Dont miss to read the Interview questions from this Topic in the end 💀😋 ------------------------------------- 🧩 Types of Exceptions: 1. CHECKED EXCEPTIONS → Problems Java expects you to handle before running (e.g., reading a missing file). ----Must fix---- 2. UNCHECKED EXCEPTIONS → Problems that happen while running (e.g., dividing by zero). 3. ERRORS (Bugs) → Serious system-level problems (e.g., memory full, system crash). ------------------------------------- 🧠 Simple Example: class ExceptionTypesStory { public static void main(String[] args) { try { int apples = 5; int kids = 0; int eachGets = apples / kids; // Oops! Unchecked exception System.out.println("Each kid gets: " + eachGets); } catch (ArithmeticException e) { System.out.println("Oops! Can't divide apples by zero kids."); } //See here how I handled the error 👇🏃 try { Thread.sleep(500); // Checked exception } catch (InterruptedException e) { System.out.println("Someone woke me up too early!"); } System.out.println("###_Story_over_###"); //Everything handled 😜smoothly } } ------------------------------------- ⚙️ Real-World Connections: 1. Online Shopping App– Item goes out of stock → Exception handled, shows “Out of Stock” instead of crashing. 2. Bank App – Network drops during payment → Checked exception, retried safely. 3. Music Player – Song file missing → Checked exception handled, plays next song. 5. Web Browser – Out of memory loading heavy tabs → Error, can’t recover easily. ------------------------------------- 🔥 Interview-Style Quick Questions — Exceptions in Java 1️⃣ What is the difference between Checked and Unchecked Exceptions? 2️⃣ Can we handle Errors using try-catch? If not, why? 3️⃣ Is it mandatory to handle Checked Exceptions? 4️⃣ What happens if you don’t handle an Unchecked Exception? 5️⃣ Can a single catch block handle multiple exceptions? 6️⃣ What is the parent class of all exceptions in Java? 7️⃣ What happens if you put finally block before catch? 8️⃣ Can we have a try block without catch? 9️⃣ What’s the difference between throw and throws in exception context? 🔟 Why is Exception Handling important in large-scale applications? #Java #100DaysOfJava #CodingJourney #ExceptionHandling #SoftwareEngineer #SoftwareEngineering #LearningNeverStops #MERNtoJavaJourney
To view or add a comment, sign in
-
-
Inheritance in java with real time example Concept: Inheritance in Java Definition: Inheritance is an OOP principle where one class (child/subclass) acquires the properties and behaviors of another class (parent/superclass). It represents an “IS-A” relationship. Example: A Dog is a Animal, a Car is a Vehicle. Why it matters: Inheritance allows one class to acquire properties and behaviors of another. It helps in code reusability, hierarchy building, and supports polymorphism — making programs easier to extend and maintain. 1. Promotes code reusability — common logic is written once in a parent class. 2. Enables hierarchical structure — natural real-world modeling. 3. Supports polymorphism — methods can be overridden for specialized behavior. 4. Reduces redundancy and improves maintainability. Example / Scenario: Real-Life Example: Vehicle System Every Car, Bike, or Truck is a Vehicle. They all share basic features (start, stop), but each can have its own behavior too. class Vehicle { void start() { System.out.println("Vehicle starting..."); } } class Car extends Vehicle { void start() { System.out.println("Car starts with key ignition."); } void openDoors() { System.out.println("Doors opened!"); } } Car car = new Car(); car.start(); // "Car starts with key ignition." car.openDoors(); Real-Life Analogy: A child inherits qualities from parents but also has unique traits. Likewise, subclasses inherit from parent classes and extend functionality. 📌 Takeaway: Inheritance helps you reuse, extend, and organize your code — just like traits passed from one generation to the next. Types of Inheritance in java : 1️⃣ Single Inheritance – One class inherits from another. class Animal { void eat(){} } class Dog extends Animal { void bark(){} } 2️⃣ Multilevel Inheritance – Class inherits from another class which inherits from a third. class Puppy extends Dog {} 3️⃣ Hierarchical Inheritance – Multiple classes share one parent. class Car extends Vehicle {} class Bike extends Vehicle {} 4️⃣ Multiple Inheritance – ❌ Not supported with classes (avoids ambiguity). ✅ Supported via Interfaces. interface A{} interface B{} class C implements A,B{} 5️⃣ Hybrid Inheritance – Combination of multiple and hierarchical (via interfaces). Takeaway: Inheritance allows you to reuse, extend, and organize code efficiently — just like traits passed from parents to children. #Java #Inheritance #OOPs #LearnJava #ProgrammingConcepts #SoftwareDevelopment #CodeReusability #Polymorphism #JavaLearning #ObjectOrientedProgramming
To view or add a comment, sign in
-
💡 My Java Journey: Understanding Encapsulation, Inheritance, Polymorphism & Abstraction When I first heard these four words — Encapsulation, Inheritance, Polymorphism, and Abstraction — I honestly thought Java was trying to speak another language 😅 They sounded complex and intimidating… But once I truly understood them, they changed how I think about writing clean, reusable, and scalable code. Here’s how I break them down 👇 🔒 Encapsulation The concept that taught me: “Protect your data, don’t expose it unnecessarily.” Encapsulation is all about binding data and methods together inside a single unit (class), and controlling access through getters/setters. Example: public class Employee { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } } ✅ Keeps your variables safe from accidental modification. ✅ Promotes modular, maintainable code. Think of it as data hiding with discipline. 🧬 Inheritance This one blew my mind when I realized how powerful code reusability could be. Inheritance means one class can acquire properties and behaviors of another class. Example: class Animal { void eat() { System.out.println("eating..."); } } class Dog extends Animal { void bark() { System.out.println("barking..."); } } ✅ Dog automatically inherits eat() from Animal. ✅ Avoids code duplication — and keeps your code DRY. It’s like saying: “Why reinvent the wheel when you can extend it?” 😎 🔁 Polymorphism A fancy word that simply means — one action, many forms. There are two main types: Compile-time (Method Overloading) Runtime (Method Overriding) Example: class Shape { void draw() { System.out.println("Drawing shape"); } } class Circle extends Shape { void draw() { System.out.println("Drawing circle"); } } ✅ The same method name behaves differently depending on the object type. That’s the beauty of dynamic behavior in Java. 🧠 Abstraction Abstraction taught me to focus on what the code does, not how it does it. Example: abstract class Vehicle { abstract void start(); } class Car extends Vehicle { void start() { System.out.println("Car starts with a key"); } } ✅ You define the “idea” in the abstract class. ✅ Concrete classes bring those ideas to life. Abstraction = Hiding complexity, showing functionality. 💬 My Takeaway ConceptWhat It TeachesEncapsulationKeep data safe & structuredInheritanceReuse code smartlyPolymorphismWrite flexible & dynamic codeAbstractionSimplify complex systems Understanding these four pillars changed the way I design every class and method. They’re not just OOP concepts — they’re principles of good software thinking. 💻✨ 💬 Your Turn: Which OOP concept took you the longest to truly understand — and how did you finally “get it”? Share your story 👇 — let’s learn from each other!
To view or add a comment, sign in
-
🎯 Day 15 of My Java Learning Journey 🎯 . Hey everyone! 👋 .. Today I explored Selection Statements again — but this time, I focused on finding the smallest number among four values using if-else if ladder in Java. Here’s the code I wrote 👇 --------------------------------------code start--------------------------------------- public class FindSmallerNumberDemo2 { public static void main(String[] args) { int l = 1; int m = 2; int n = 3; int o = 4; if (l < m && l < n && l < o) { System.out.println("l is smaller"); } else if (m < o && m < n && m < l) { System.out.println("m is smaller"); } else if (o < n && o < m && o < l) { System.out.println("o is smaller"); } else { System.out.println("n is smaller"); } } } --------------------------------------code output---------------------------------- l is smaller number -------------------------------------code end--------------------------------------- . 💡 Explanation: I’ve declared four integer variables — l, m, n, and o. The if statement checks multiple conditions using logical AND (&&) to make sure one number is smaller than all others. . If the first condition fails, the program moves to the next else if condition. Finally, if none of the earlier conditions are true, the else block executes — meaning the last variable n is the smallest. . 🧠 This program is a simple way to understand how comparison and logical operators work together in decision-making statements. In the next few posts, I’ll share more concepts related to selection and looping statements in Java 🚀 . #Day15 #JavaLearningJourney #100DaysOfCode #LearnJava #Programming #DevOps #Coding #JavaBeginners #SelectionStatement #IfElseInJava .
To view or add a comment, sign in
-
-
🌟 Day 14 of My Java Learning Journey 🔥 💯 Hey everyone! 👋 ~ Today’s topic was all about decision-making in Java — how a program chooses which path to follow based on given conditions. 💡 . I explored how to find the greatest number among multiple values using nested if-else statements, one of the core parts of selection statements in Java. 💻 Here’s the code I worked on today: 👇 -------------------------------------code start-------------------------------------- public class FindGreaterNumberDemo2 { public static void main(String[] args) { int p = 11; int q = 22; int r = 33; int s = 44; if (p > r && p > s && p > q) { System.out.println("p is greater number "); } else if (q > s && q > p && q > r) { System.out.println("q is greater number"); } else if (r > p && r > s && r > q) { System.out.println("r is greater number"); } else { System.out.println("s is greater number"); } } } -------------------------------------code output------------------------------------ s is greater number ---------------------------------------code end-------------------------------------- . 🔍 Explanation: We have four integer variables: p, q, r, and s. Using an if-else-if ladder, we compare each number with the others using the logical AND (&&) operator. The first condition that turns out true will print which number is the greatest. If none of them match, the else block executes, showing that s is the greatest. . 💡 Key Takeaway: Selection statements like if, else if, and else help control the program’s logic — deciding what happens next depending on the condition. . 🚀 What’s next? In the upcoming posts, I’ll share many more real-world examples related to selection statements, so we can deeply understand how decision-making works in Java programs. Stay tuned — it’s gonna get crazy cool and more practical! 💻🔥 . #Java #100DaysOfCode #Day14 #JavaLearningJourney #FlowControl #IfElse #SelectionStatements #DevOps #Programming #CodingJourney #LearnJava #TechLearner #CodeNewbie .
To view or add a comment, sign in
-
-
Understanding the Flow of a Modern Python Web App (FastAPI + Uvicorn + Pydantic) 🧠 FastAPI has quickly become one of the most popular Python frameworks for building web APIs. But have you ever wondered what really happens under the hood when you hit an endpoint like /books/1? Let’s take a step back and understand the flow of a FastAPI application — without diving into code. ⚙️ The Core Players A typical FastAPI project involves four key components working in harmony: ⚡ Uvicorn - ASGI web server - Handles incoming HTTP connections 🚏 Starlette - Web toolkit - Manages routing, middleware, sessions 🧩 FastAPI - Web framework - Defines routes, request/response models ✅ Pydantic - Data validation - Validates and structures input/output data Together, they form a lightweight yet powerful stack for building APIs that are type-safe, fast, and scalable. 🔄 The Flow: From Request to Response 1️⃣ The Client Sends a Request A browser, mobile app, or Postman sends a request like: GET /books/1 2️⃣ Uvicorn Receives It Uvicorn — the ASGI server — listens on a port (like :8000) and forwards the request into your FastAPI app. 3️⃣ FastAPI + Starlette Handle the Route FastAPI uses Starlette’s routing system to find the right endpoint. If your route is @app.get("/books/{id}"), this function gets triggered. 4️⃣ Pydantic Validates Input Before your function runs, Pydantic ensures the input matches the expected schema (for example, id must be an integer). If validation fails — FastAPI automatically returns a clear error message. No manual checks needed. 5️⃣ Business Logic Executes This is where your Python code runs — fetching data from the database, performing calculations, invoking other APIs or returning results. 6️⃣ Response Is Built and Validated Again Your endpoint returns a Python object. FastAPI validates it again with Pydantic (so your output is also clean) and converts it to JSON. 7️⃣ Uvicorn Sends It Back The final JSON response is sent back to the client — fast, validated, and structured. 🗄️ Adding the Database Layer Most real-world projects also connect to a database (like PostgreSQL or MySQL). Here’s how that fits into the same flow: FastAPI provides a database session (via dependency injection). Your logic layer talks to the ORM (like SQLAlchemy), which converts Python models into SQL queries. The database executes those queries and returns results to FastAPI. FastAPI sends the validated JSON response back to the client. 🌟 Why This Architecture Works So Well ✅ Fast — Built for async performance with Uvicorn and Starlette ✅ Safe — Validation at both input and output using Pydantic ✅ Developer-friendly — Automatic Swagger docs at /docs ✅ Scalable — Can run with multiple Uvicorn workers behind Gunicorn ✅ Modern — Fully supports async/await and type hints Next time you run uvicorn main:app --reload, you’ll know exactly what’s happening behind the scenes. ⚙️ #PythonWeb #FastAPI #UVICORN #ModernWebApp
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development