Another form of polymorphism in Java appears through method overriding. This happens when a child class provides its own implementation of a method that already exists in the parent class. Things that became clear : • method overriding occurs during inheritance • the child class keeps the same method name and parameters as the parent class • the implementation of the method is changed in the child class • the method that runs is decided at runtime • this is known as runtime polymorphism A simple example shows how this works : class Parent { void show() { System.out.println("Parent method"); } } class Child extends Parent { void show() { System.out.println("Child method"); } } When an object of the child class is used, the child’s version of the method is executed. This mechanism allows subclasses to adjust behaviour while still keeping the structure defined by the parent class. #java #oop #programming #learning #dsajourney
Lakhyadeep Sen’s Post
More Relevant Posts
-
While studying method overriding, a few rules also became clear that control how overriding works in Java. These rules ensure that the behaviour of inherited methods stays consistent across parent and child classes. Things that became clear : • the method name and parameter list must remain the same • the return type must be the same or related to the parent method • the access level of the method cannot be reduced in the child class • private methods do not participate in inheritance and therefore cannot be overridden • methods declared as final cannot be overridden • if a method is abstract in the parent class, the child class must provide its implementation These rules help Java maintain a predictable structure when classes inherit behaviour from one another. Understanding these restrictions made it easier to see how inheritance and polymorphism work together in object oriented programs. #java #oop #programming #learning #dsajourney
To view or add a comment, sign in
-
Inheritance in Java Inheritance is one of the important concepts in Object-Oriented Programming (OOP). It allows one class to inherit the properties and methods of another class. In simple terms, a child class can reuse the features of a parent class, which helps in code reusability and reducing duplication. Types of Inheritance 1️⃣ Single Inheritance – One child class inherits from one parent class. 2️⃣ Multilevel Inheritance – A class inherits from another class, which itself inherits from another class. 3️⃣ Hierarchical Inheritance – Multiple child classes inherit from one parent class. 4️⃣ Multiple Inheritance – One class inherits from multiple classes (not supported with classes in Java, but possible using interfaces). 5️⃣ Hybrid Inheritance – Combination of different inheritance types. 6️⃣ Cyclic Inheritance - It occurs when a class tries to inherit from itself directly or indirectly, creating a loop in the inheritance hierarchy. TAP Academy #Java #OOP #Inheritance #Programming #LearningJourney
To view or add a comment, sign in
-
-
Day 8 of My Java Learning Journey ☕💻 Today I continued strengthening my core Java fundamentals and focused on understanding Method Overloading and basic Inheritance concepts. What I practiced today: • Implemented method overloading by creating an Area Calculator for Square, Rectangle, and Circle • Learned how Java decides which method to call at compile time (Compile-Time Polymorphism) • Practiced taking user input using the Scanner class • Explored the basics of Inheritance using parent and child classes • Understood how child classes can access methods from parent classes One key takeaway today: Writing small programs helps reinforce concepts much better than just reading theory. Next on the learning roadmap: • Method Overriding • Runtime Polymorphism • Deeper understanding of Object-Oriented Programming in Java Step by step, building stronger backend fundamentals. #Java #LearningInPublic #Programming #BackendDevelopment #100DaysOfCode #JavaDeveloper
To view or add a comment, sign in
-
🚀 Day 14/45 – Understanding Inheritance in Java On Day 14 of my Java learning journey, I explored the concept of Inheritance, one of the core pillars of Object-Oriented Programming. Inheritance allows one class to acquire the properties and behaviors of another class, promoting code reuse and better program structure. 📚 What I Learned Today Today I learned: ✔ What inheritance is and how it works ✔ Parent (base) class and child (derived) class ✔ Using the extends keyword in Java ✔ Types of inheritance such as single and multilevel 💻 Practice Work To apply my learning, I implemented: • A basic inheritance example using person and student classes • An employee-manager example to demonstrate inherited properties 🎯 Key Takeaway Inheritance helps reduce code duplication and makes programs more organized and scalable. It is a powerful feature that plays a key role in building real-world applications.Understanding OOP concepts step by step is making programming more structured and logical. #Java #Programming #LearningInPublic #CodingJourney #SoftwareDevelopment #OOP
To view or add a comment, sign in
-
🚀 Java Learning Journey – Day 5 Why Java Says "No" to Multiple Inheritance (and "Yes" to Interfaces) 💎 Ever wondered why Java doesn't allow a class to inherit from two parents? It all comes down to the Diamond Problem. When two parent classes have the same method, the compiler gets confused: "Which one should I use?" To keep things clean and prevent bugs, Java blocks this at the class level. But wait—you can still achieve the same goal! 💡 By using Interfaces, you get the flexibility of multiple inheritance without the ambiguity. Check out this quick visual guide I put together to break it down. 👇 #Java #Programming #ObjectOrientedProgramming #SoftwareDevelopment #CodingTips #TechCommunity
To view or add a comment, sign in
-
-
🚀 Day 73/100 of My Java Programming Series ☕💻 Today, I learned and practiced Method Overloading in Java — an important concept of compile-time polymorphism. 📌 What I explored today: ✅ What is Method Overloading ✅ Same method name with different parameters ✅ Changing number of arguments ✅ Changing data types of arguments ✅ Improving code readability and reusability ✅ Real-time examples for better understanding 💡 Key takeaway:Method Overloading allows us to define multiple methods with the same name but with different parameter lists. It helps make programs more flexible, organized, and easier to understand. 🧠 This concept is very useful in writing cleaner code and understanding how Java supports polymorphism. 🔥 Day 73 completed. Still learning, still growing! #Java #JavaProgramming #OOP #MethodOverloading #Polymorphism #100DaysOfCode #CodingJourney #Programming #SoftwareDevelopment #JavaDeveloper #LearningJourney10000 Coders Meghana M
To view or add a comment, sign in
-
🚀 Starting My Java Learning Journey – Day 8 🔹 Topic: Methods in Java A method is a block of code that performs a specific task. Methods help make programs organized, reusable, and easier to read. returnType – type of value the method returns (use void if it returns nothing) methodName – name of the method parameters – input values the method takes 📌 Example Program public class Main { // Method to add two numbers static int addNumbers(int a, int b) { return a + b; } public static void main(String[] args) { int sum = addNumbers(10, 20); System.out.println("Sum: " + sum); } } Output: Sum: 30 💡 Key Points: Methods avoid code repetition Methods can take inputs (parameters) and return outputs Helps in modular programming #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaMethods
To view or add a comment, sign in
-
🚀 Java Learning Journey – Day 8 Today I learned about Polymorphism in Java, one of the key concepts of Object-Oriented Programming. Polymorphism means one action can be performed in multiple ways. A simple real-world example is a payment system. A customer can make a payment using different methods like Credit Card, UPI, or Cash. Even though the method changes, the core action remains the same: Payment. In Java, polymorphism allows a parent class reference to call different implementations of a method depending on the object type. This makes the code more flexible, reusable, and easier to maintain. Understanding polymorphism helps developers design systems that can easily support multiple behaviors with a single interface. #Java #OOP #Polymorphism #JavaDeveloper #LearningInPublic #Programming #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 8 of My Java Learning Journey Today I learned how Java handles input using BufferedReader & InputStreamReader 💻 🔹 Key Concepts I Covered: 👉 What is InputStreamReader 👉 What is BufferedReader 👉 Difference between read() and readLine() 👉 How to take character input 👉 How to take full string input 💡 Why this is important? ✔ Faster input than Scanner ✔ Used in competitive programming ✔ Helps understand low-level input handling 🧠 What I practiced today: ✅ Program to take a single character input ✅ Program to take a full string input 🔥 Small Step Today, Big Impact Tomorrow! Aman Soni Consistency is the key — learning something new every day 💯 #Java #CodingJourney #100DaysOfCode #Programming #Learning #BufferedReader #JavaDeveloper #CodeNewbie #VidhyaCodeGurukul
To view or add a comment, sign in
-
-
🚀 Learning Java – Understanding the Static Keyword Today I completed the "Static" concept in Java on TAP Academy. In Java, the keyword static is used for variables, methods, blocks, and nested classes. It means the member belongs to the class, not to individual objects. 1️⃣ Static Variable (Class Variable) A variable declared with static is shared by all objects of the class. Only one copy exists in memory. 2️⃣ Static Method A method declared as static can be called without creating an object. It can only directly access static variables and static methods. 3️⃣ Static Block Used for initializing static variables. It runs only once when the class is loaded. 4️⃣ Static Nested Class A class declared inside another class with static. It can access only static members of the outer class. #Java #Programming #Learning #TAPAcademy #SoftwareDevelopment #BTechStudent
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