Day 10/100 – Java Practice Challenge 🚀 Continuing my #100DaysOfCode journey with another important Java concept. 🔹 Topic Covered: Polymorphism Polymorphism means “many forms” — the same method behaves differently depending on the object. 💻 Practice Code: 🔸 Example Program class Animal { void sound() { System.out.println("Animal makes sound"); } } class Dog extends Animal { @Override void sound() { System.out.println("Dog barks"); } } public class Main { public static void main(String[] args) { Animal a = new Dog(); // Upcasting a.sound(); // Runtime polymorphism } } 📌 Key Learnings: ✔️ Same method → different behavior ✔️ Achieved using method overriding ✔️ Based on object type (runtime) 🎯 Focus: Understanding dynamic behavior using inheritance and method overriding 🔥 Interview Insight: Polymorphism is a core OOP concept and widely used in real-world applications. #Java #100DaysOfCode #Polymorphism #OOP #JavaDeveloper #Programming #LearningInPublic
Java Polymorphism Practice with Method Overriding
More Relevant Posts
-
🔹 Title: Solving “Plus Minus” Problem in Java 📊 🔹 Description: Today I solved the Plus Minus problem, where the goal is to calculate the ratios of positive, negative, and zero values in an array. The challenge was not just counting the values, but also formatting the output correctly to 6 decimal places. 💡 Approach: Traverse the array and count positives, negatives, and zeros Divide each count by the total number of elements Print results using precise formatting 🔹 What I learned: ✔ Importance of output formatting ✔ Handling edge cases (like zeros) ✔ Writing clean and efficient Java code Consistency in practicing such problems really strengthens core programming skills. 🚀 #Java #Coding #ProblemSolving #Programming #DataStructures
To view or add a comment, sign in
-
-
🚀 Exploring Method Overloading with Varargs in Java Today, I worked on an interesting Java problem that helped me strengthen my understanding of Compile-Time Polymorphism and Varargs (Variable Arguments). 🔹 Problem Statement: Design a VarargsCalculator class with overloaded methods to calculate the sum of: Multiple integers Multiple double values 🔹 Key Concepts Used: ✔ Method Overloading ✔ Varargs (int..., double...) ✔ Switch-case for dynamic method selection ✔ For-each loop for efficient iteration 🔹 Learning Outcome: This problem clearly demonstrates how Java allows the same method name to handle different types and number of inputs, depending on the parameters passed. It also shows how varargs simplify handling multiple inputs without explicitly creating arrays. 💡 Key Insight: Varargs in Java internally behave like arrays, making code more flexible and readable. 🔹 Sample Output: Sum of integers: 10 Sum of doubles: 7.0 📌 Practicing such problems is helping me improve my problem-solving skills and deepen my understanding of core Java concepts. #Java #CoreJava #MethodOverloading #Varargs #Programming #Coding #100DaysOfCode #DeveloperJourney #JavaDeveloper #LearningInPublic
To view or add a comment, sign in
-
-
📘 Day 25 – Unlocking the Magic of Java Casting Today I dove deep into non-primitive type casting in Java and had that haha moment! 💡 ✨ Upcasting – Treating a subclass object as a superclass reference. It makes my code cleaner, flexible, and ready for change. ⚡ Downcasting – Converting back safely to a subclass. Done wrong, it throws ClassCastException, but done right, it’s pure power. 🛡 instanceof operator – My safety net! It checks object type before casting, keeping runtime errors away. Seeing objects flow up and down the hierarchy revealed the true beauty of polymorphism, code that’s adaptable, maintainable, and future-proof. 💬 What really clicked: Java isn’t just about syntax; it’s about managing relationships between objects smartly. This makes every line of code safer, cleaner, and smarter. #Java #OOP #Polymorphism #Upcasting #Downcasting #ClassCastException #InstanceOf #DailyLearning #CodeBetter #ProgrammingJourney #DevLife
To view or add a comment, sign in
-
Today I explored some fundamental yet powerful concepts in Java that every developer should have a strong grip on: 🔹 Static Methods & VariablesUnderstanding how static members are shared across all objects really changed how I think about memory and efficiency. It’s amazing how a simple static keyword can help track object creation and maintain shared data seamlessly. 🔹 Constructor Overloading & this KeywordThis concept made object initialization much more flexible. Using multiple constructors and the this keyword not only improves code readability but also avoids redundancy. 💡 What I realized:Strong basics are the real game-changer. These concepts might look simple, but they build the foundation for writing clean, scalable, and efficient code. 📌 Consistency in learning > Complexity in topics I’m currently focusing on strengthening my core Java skills and building projects around them. Every small concept learned today contributes to becoming a better developer tomorrow. #Java #Programming #CodingJourney #DeveloperLife #JavaDeveloper #Learning #TechSkills #Coding #StudentDeveloper
To view or add a comment, sign in
-
Day 73 of #90DaysDSAChallenge Solved LeetCode 451: Sort Characters By Frequency Learned an important Java design concept today. Problem Overview: The task was to sort characters in a string based on descending frequency. What confused me initially: Why create a separate Freq class instead of just using HashMap and PriorityQueue directly? Key Learning: PriorityQueue stores one complete object at a time. For this problem, each item needs two pieces of data together: Character Frequency Example: Instead of storing: e and 2 separately We package them as: Freq('e', 2) That custom class acts like a container holding both values in one object, so PriorityQueue can compare and sort them correctly. Why this matters: This taught me that custom classes in Java are often not about complexity, they simply bundle related data into one manageable unit. Alternative approach: We can also use Map.Entry<Character, Integer> instead of creating a custom class, but building Freq makes the logic easier to understand while learning. Today’s takeaway: Not every class is for business logic — sometimes it exists just to package data cleanly. #Java #90DaysDSAChallenge #LeetCode #PriorityQueue #HashMap #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
One Java concept completely changed how I write code: Encapsulation. At first, I thought Java was just about writing classes and methods or more over object creation But when I learned Encapsulation, I realized: 👉 Good code is not just working code. 👉 Good code protects its data. ☕ What is Encapsulation in Java? Encapsulation means: Wrapping data (variables) and code (methods) together into a single unit — a class. And controlling access to data using: 🔹 private variables 🔹 public getter/setter methods 💡 Why Encapsulation Matters: 🔹 Protects data from accidental changes 🔹 Improves code security 🔹 Makes code easier to maintain 🔹 Helps in building large applications 🎯 My Learning Takeaway: 👉 Encapsulation is not just a concept—it’s discipline. 👉 Clean code today saves debugging tomorrow. 👉 Understanding concepts deeply is better than memorizing syntax. #Java #JavaDeveloper #ObjectOrientedProgramming #OOP #Programming #SoftwareDevelopment #CodingJourney #TechLearning
To view or add a comment, sign in
-
Day 11/100 – Java Practice Challenge 🚀 Continuing my #100DaysOfCode journey with another important Java concept. 🔹 Topic Covered: Compile-time vs Runtime Polymorphism 💻 Practice Code: 🔸 Compile-time Polymorphism (Method Overloading) class Calculator { int add(int a, int b) { return a + b; } int add(int a, int b, int c) { return a + b + c; } } 🔸 Runtime Polymorphism (Method Overriding) class Animal { void sound() { System.out.println("Animal sound"); } } class Cat extends Animal { @Override void sound() { System.out.println("Cat meows"); } } public class Main { public static void main(String[] args) { // Compile-time Calculator c = new Calculator(); System.out.println(c.add(10, 20)); System.out.println(c.add(10, 20, 30)); // Runtime Animal a = new Cat(); a.sound(); } } 📌 Key Learnings: ✔️ Compile-time → method decided at compile time ✔️ Runtime → method decided at runtime ✔️ Overloading vs Overriding difference 🎯 Focus: Understanding how Java resolves method calls 🔥 Interview Insight: Difference between compile-time and runtime polymorphism is one of the most frequently asked Java interview questions. #Java #100DaysOfCode #MethodOverloading #MethodOverriding #Polymorphism #JavaDeveloper #Programming #LearningInPublic
To view or add a comment, sign in
-
Day 53 of Sharing What I’ve Learned 🚀 ArrayDeque in Java — Fast & Flexible Queue Alternative After understanding how LinkedList works as a Queue, I explored a more optimized and powerful structure in the Java Collections Framework — ArrayDeque 🔹 What is ArrayDeque? ArrayDeque is a resizable array-based implementation of a Deque (Double-Ended Queue). 👉 It allows insertion and deletion from both ends efficiently. 🔹 Why use ArrayDeque over LinkedList? ✔ Faster Performance No node traversal → better speed compared to LinkedList. ✔ No Extra Memory Overhead Doesn’t store pointers like LinkedList → more memory efficient. ✔ Better Cache Performance Elements are stored contiguously → faster access. ✔ Acts as Stack + Queue Can be used as: Stack (LIFO) Queue (FIFO) Deque (both ends) 🔹 Key Operations ✔ addFirst() / addLast() ✔ removeFirst() / removeLast() ✔ peekFirst() / peekLast() 🔹 When should we use ArrayDeque? 👉 Use ArrayDeque when: ✔ You need fast insertions/deletions at both ends ✔ You want a better alternative to Stack or LinkedList ✔ Performance matters (less overhead) 🔹 When NOT to use? ❌ When you need random access (indexing) ❌ When frequent middle operations are required 🔹 Key Insight 💡 Not all Queues are equal — 👉 Choosing the right implementation (LinkedList vs ArrayDeque) can significantly impact performance. 🔹 Day 53 Realization 🎯 Efficiency isn’t just about solving problems — 👉 It’s about solving them smartly with the right tools. #Java #ArrayDeque #DataStructures #CollectionsFramework #Programming #DeveloperJourney #100DaysOfCode #Day53 Grateful for guidance from, Sharath R TAP Academy
To view or add a comment, sign in
-
-
Day 8/100 – Java Practice Challenge 🚀 Continuing my #100DaysOfCode journey with another important Java concept. 🔹 Topic Covered: Upcasting and Downcasting Upcasting and downcasting are important concepts in Java that deal with type conversion between parent and child classes. They are widely used in real-world applications, especially in polymorphism. 💻 Practice Code: 🔸 Example Program class Animal { void sound() { System.out.println("Animal makes a sound"); } } class Dog extends Animal { void bark() { System.out.println("Dog barks"); } } public class Main { public static void main(String[] args) { // 🔹 Upcasting (Child → Parent) Animal a = new Dog(); a.sound(); // 🔹 Downcasting (Parent → Child) Dog d = (Dog) a; d.bark(); } } 📌 Key Learnings: ✔️ Upcasting is automatic and safe ✔️ Downcasting requires explicit casting ✔️ Downcasting can cause ClassCastException if not handled properly ✔️ Helps achieve runtime polymorphism 🎯 Focus: Understanding how objects behave when referenced by parent vs child types ⚡ Types of Casting: 👉 Upcasting (Implicit) 👉 Downcasting (Explicit) 🔥 Interview Insight: Upcasting and downcasting are frequently asked in interviews to test your understanding of polymorphism and object behavior in Java. #Java #100DaysOfCode #Upcasting #Downcasting #JavaDeveloper #Programming #LearningInPublic
To view or add a comment, sign in
-
🚀 Mastering Java Through LeetCode 🧠 Day 32 Today I solved an Easy-level Tree problem that strengthened my understanding of Recursion + Depth Calculation — a fundamental concept for tree-based problems 📌 LeetCode Problem Solved: Q.104. Maximum Depth of Binary Tree 💭 Problem Summary: Given a binary tree, the task is to find the maximum depth — i.e., the number of nodes along the longest path from root to leaf. 🧠 Approach (Optimal): Instead of iterating level by level, I used a clean recursive approach: ✔️ If node is null → return 0 ✔️ Recursively calculate left subtree depth ✔️ Recursively calculate right subtree depth ✔️ Return 1 + max(left, right) ⚡ Key Learning: Recursion makes tree problems much simpler when you think in terms of “what should each function return for a node?” Complexity: Time: O(n) Space: O(h) Takeaway: Tree problems become easier once you master recursion and start recognizing patterns. Consistency is the key — showing up every day #Day32 #LeetCode #Java #DSA #CodingJourney #Recursion #BinaryTree #100DaysOfCode #SoftwareEngineering
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