🚀 Day 5 — The “Polymorphism Trap” That Even 5+ Year Devs Fall Into 😵💫 Everyone thinks they know Polymorphism… Until Overloading and Overriding collide inside the same class 🔥 class Parent { void calc(Number n) { System.out.println("Parent Number"); } void calc(Integer i) { System.out.println("Parent Integer"); } } class Child extends Parent { @Override void calc(Number n) { System.out.println("Child Number"); } } public class PolymorphPuzzle { public static void main(String[] args) { Parent p = new Child(); p.calc(null); } } 💭 Question: What will be the output? 1️⃣ Parent Number 2️⃣ Parent Integer 3️⃣ Child Number 4️⃣ Compile-time Error 💬 Drop your answer in the comments 👇 90% developers get this wrong — can you get it right without running the code? 😎 Let’s see who’s the real Java champ 🧠🔥 #Java #Polymorphism #CodingChallenge #SpringBoot #InterviewQuestion #Day5Challenge #JavaDeveloper #LearnJava #OOPsConcepts
"Polymorphism Trap: Overloading vs Overriding in Java"
More Relevant Posts
-
Day 89 of #100DaysOfCode Solved Find Numbers with Even Number of Digits in Java 🔢 Approach The goal of this problem was to count how many integers in a given array have an even number of digits. I implemented two methods: findNumbers(int[] nums): This is the main function that iterates through every number in the input array nums. isEvenOrOdd(int n): This helper function takes an integer and determines if its digit count is even or odd. Inside the helper function, I used a while loop to count the digits: I initialized a count to 0. The loop continues as long as $n > 0$. In each iteration, I increment count and then perform integer division by 10 (n = n / 10) to remove the least significant digit. Finally, I return true if the total count of digits is even (count \% 2 == 0). This efficient, digit-by-digit checking approach resulted in a strong performance, beating 98.90% of other submissions. #Java #100DaysOfCode #LeetCode #CodingChallenge #Algorithms #Array #ProblemSolving #Optimization
To view or add a comment, sign in
-
-
Day 19 of #100DaysOfLeetCode 💻 Today’s challenge was about finding two unique numbers in an array where every other number appears twice. At first, I tried using an ArrayList — adding numbers if they weren’t present and removing them if they already existed. The logic worked, but I ran into type conversion issues (Object cannot be converted to int). That’s when I learned the importance of using generics in Java (ArrayList<Integer> instead of raw ArrayList). Small syntax details, but they make all the difference! 🔍 Key takeaways: Always specify the data type in collections. Understand how remove() behaves differently for index vs value. Even a brute-force approach can teach valuable debugging lessons. #Day19 #LeetCode #Java #CodingJourney #100DaysOfCode #Debugging #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 45 of #LeetCode Journey 🚀 ✅ Problem: Count and Say 📘 Language: Java 🔹 Status: Accepted (30/30 test cases passed) 🔹 Runtime: 4 ms | Beats 55.38% 🔹 Memory: 41.86 MB 🧠 Concept: This problem is about generating the n-th term in the “count and say” sequence. Each term is built by describing the previous term — count the number of digits and say them in order. 🧩 Approach: Start with "1". For each iteration, use a StringBuilder to construct the next sequence. Track consecutive digits using a counter. Append the count and digit when the sequence changes. 💡 Efficient string manipulation and iteration give optimal performance. 🔥 Every solved problem builds confidence. One step closer to mastering patterns in strings! #Day45 #LeetCode #Java #CodingChallenge #ProblemSolving #CountAndSay #50DaysOfCode
To view or add a comment, sign in
-
-
Hey Uplifters! 👋 Problem of the Day: (23-10-2025) 3461 - Check If Digits Are Equal in String After Operations I Problem in short: • You’re given a string s consisting of digits. • In each operation, replace every pair of consecutive digits with their sum mod 10, until only two digits remain. • Finally, return true if the last two digits are the same - otherwise false. 💡 Intuition: • We directly simulate the process as described - at every step, build a new string using the sum (mod 10) of adjacent digits until only two remain. • This is a beginner-friendly brute force approach that clearly shows the transformation process. 🧩 Approach: • Use a StringBuilder in java (Or normal string in cpp) for efficient string manipulation. • Repeatedly form a new string with (v1 + v2) % 10 for each adjacent pair. • Stop when only two digits are left, and compare them. Code Implementation with Explanation (Java): 👉 https://lnkd.in/g2rAty_T (GitHub) 👉 https://lnkd.in/gaygqRPt (Leetcode) Drop your thoughts below Let’s keep learning and growing together! 🌱 #LeetCode #POTD #ProblemOfTheDay #DailyChallenge #CodingChallenge #DataStructures #Algorithms #BinarySearch #ProblemSolving #Java #JavaProgramming #LearnToCode #CodeNewbie #TechCommunity #SoftwareDevelopment #Programming
To view or add a comment, sign in
-
🚀 Day 26 of 100 Days of LeetCode 📘 Problem: Search a 2D Matrix 💻 Language: Java ✅ Status: Accepted — Runtime: ⚡ 0 ms (Beats 100%) Today’s problem focused on searching efficiently within a 2D matrix — a great exercise for understanding nested loops, traversal logic, and time optimization. While this version used a simple brute-force approach, it served as a good refresher on matrix iteration patterns before moving on to more optimized binary search techniques in 2D grids. ✨ Key Learnings: Matrix traversal can be intuitive when visualized 🔢 Always consider both brute-force and optimized approaches — understanding both is key to depth of knowledge Writing clean, readable code matters as much as optimizing it Each problem solved is another small brick in the foundation of strong problem-solving skills 💪 #Day26 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #SoftwareDevelopment #Matrix #KeepLearning #CodeEveryday
To view or add a comment, sign in
-
-
🚀 Day 18/100 of #100DaysOfCode ✅ Solved “Isomorphic Strings” (LeetCode #205) using Java! 🧩 Problem: Given two strings s and t, determine if they are isomorphic. 👉 Two strings are isomorphic if characters in one string can be replaced to get the other — while keeping order and unique mapping intact. 🧠 Approach: Used a HashMap to store the mapping of characters from s → t. Checked if each character in s has a consistent mapping in t. Also ensured that no two characters in s map to the same character in t. ✨ Example: s = "egg", t = "add" → true (e→a, g→d) s = "foo", t = "bar" → false 📈 Complexity: Time: O(n) Space: O(n) 💡 Key Learnings: Understood how to maintain one-to-one character mapping using a HashMap. Reinforced logic building for pattern matching between strings. 💻 Tech Used: Java | HashMap | Problem Solving #LeetCode #100DaysOfCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing #DevCommunity
To view or add a comment, sign in
-
-
📌 Day 16/100 - Reverse String (LeetCode 344) 🔹 Problem: Reverse a given string in-place — meaning you must modify the original array of characters without using extra space. 🔹 Approach: Used the two-pointer technique — one starting at the beginning and one at the end of the array. Swap characters at both pointers, then move them closer until they meet. Efficient, clean, and runs in linear time without additional memory allocation. 🔹 Key Learnings: In-place algorithms optimize space complexity significantly. The two-pointer pattern is a versatile tool for many array and string problems. Understanding mutable vs immutable structures in Java is crucial for memory efficiency. Sometimes, the simplest logic beats the most complex one. 🧠 “True efficiency lies in simplicity, not complexity.” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #TwoPointers
To view or add a comment, sign in
-
-
🎯 𝐏𝐚𝐭𝐭𝐞𝐫𝐧 𝐌𝐚𝐭𝐜𝐡𝐢𝐧𝐠 𝐟𝐨𝐫 𝐢𝐧𝐬𝐭𝐚𝐧𝐜𝐞𝐨𝐟 — 𝐂𝐥𝐞𝐚𝐧, 𝐒𝐦𝐚𝐫𝐭 & 𝐌𝐞𝐦𝐨𝐫𝐲 𝐄𝐟𝐟𝐢𝐜𝐢𝐞𝐧𝐭 Let’s be honest — we all have written code like below👇 if (obj instanceof String) { String str = (String) obj; System.out.println(str.toUpperCase()); } Looks simple , but a bit cluttered — extra casting, redundant syntax, and more memory reads than needed. 💡 𝐄𝐧𝐭𝐞𝐫 𝐏𝐚𝐭𝐭𝐞𝐫𝐧 𝐌𝐚𝐭𝐜𝐡𝐢𝐧𝐠 𝐟𝐨𝐫 𝐢𝐧𝐬𝐭𝐚𝐧𝐜𝐞𝐨𝐟 Java 14+ introduced a more elegant approach: if (obj instanceof String str) { System.out.println(str.toUpperCase()); } ✅ No need for explicit casting ✅ Cleaner and safer — variable str is automatically scoped ✅ Slightly more memory-efficient — avoids redundant reference assignments ⚙️ 𝐖𝐡𝐲 𝐈𝐭 𝐌𝐚𝐭𝐭𝐞𝐫𝐬 Pattern Matching for instanceof: ✔️Reduces boilerplate — no need to write repetitive casts ✔️Improves readability — focuses on what the logic is, not how it’s written ✔️Enhances compiler checks — prevents accidental ClassCastExceptions ✔️Memory advantage: older style created redundant variable references; pattern matching uses optimized bytecode under the hood 🔍 Real-World Example: Before 👇 if (obj instanceof Employee) { Employee e = (Employee) obj; if (e.getSalary() > 100000) { System.out.println("High earner: " + e.getName()); } } After 🚀 if (obj instanceof Employee e && e.getSalary() > 100000) { System.out.println("High earner: " + e.getName()); } Now that’s clean Java! 🧹 #Java #JavaTips #CleanCode #CodeQuality #JavaDevelopers #Programming #SoftwareEngineering #BackendDevelopment #Java17 #CodingBestPractices
To view or add a comment, sign in
-
-
#Day45 of #50DaysOfCoding Divisible Sum Pairs Problem (Java) Today, I tackled the “Divisible Sum Pairs” problem from HackerRank using Java. The objective was to identify all pairs of numbers in a list whose sum is divisible by a specified integer k. Concepts Used: - Nested loops to check every unique pair (i, j) where i < j. - Modulo operation to verify divisibility: (ar[i] + ar[j]) % k == 0. - Basic iteration and condition checking logic. Working: - Read input values n, k, and the array ar. - Iterate through all pairs. - Count how many pairs have sums divisible by k. - Print the total count. Example: If n = 6, k = 3, and ar = [1, 3, 2, 6, 1, 2], the valid pairs are (1,2), (3,6), (2,4), etc. Output: 5 Complexity: - Time Complexity: O(n²) - Space Complexity: O(1) This exercise enhanced my understanding of modulo operations, loops, and pair iteration logic — essential concepts for many coding interviews. #Java #ProblemSolving #CodingJourney #Programming #LearningEveryday #LogicBuilding #leetcode #DSA #CodingChallenge #LearnJava #CodeNewbie #Algorithms #DataStructures #TechJourney #javaProgramming #LearningInPublic #PentagonSpace
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