Inheritance gives structure. Polymorphism gives flexibility. Polymorphism means : 𝗼𝗻𝗲 𝗶𝗻𝘁𝗲𝗿𝗳𝗮𝗰𝗲, 𝗺𝗮𝗻𝘆 𝗶𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻𝘀. Consider this: class Vehicle { void start() { System.out.println("Starting vehicle"); } } class Car extends Vehicle { @Override void start() { System.out.println("Starting car"); } } Both classes have 𝘀𝘁𝗮𝗿𝘁(). But the behavior changes depending on the object. Now look at this: Vehicle v = new Car(); v.start(); Which method runs? The one inside 𝗖𝗮𝗿. This is called 𝗿𝘂𝗻𝘁𝗶𝗺𝗲 𝗽𝗼𝗹𝘆𝗺𝗼𝗿𝗽𝗵𝗶𝘀𝗺. The reference type is 𝗩𝗲𝗵𝗶𝗰𝗹𝗲. The actual object type is 𝗖𝗮𝗿. Java decides behavior at runtime. This concept allows systems to: • Be extensible • Follow open/closed principle • Reduce tight coupling Today was about: • Method overriding • Dynamic method dispatch • Why behavior depends on object type, not reference type Polymorphism is what makes OOP powerful. Without it, inheritance is just structure. #Java #OOP #Polymorphism #SoftwareDesign #CleanCode #LearningInPublic
Java Polymorphism Explained
More Relevant Posts
-
🚀 Day 85 of My 100 Days LeetCode Challenge | Java Today’s problem was a beautiful recursion + pattern observation challenge. We had to find the k-th bit in a recursively defined binary string sequence — and the string grows exponentially with each step. Clearly, constructing the entire string was not an option. The breakthrough came from understanding the structure: Each sequence is built as: S(n) = S(n-1) + "1" + reverse(invert(S(n-1))) Once I noticed the symmetry around the middle element and how the second half mirrors the first (with inversion), the solution became a clean recursive reduction instead of brute force. ✅ Problem Solved: Find K-th Bit in N-th Binary String ✔️ All test cases passed (63/63) ⏱️ Runtime: 0 ms (Beats 100%) 🧠 Approach: Recursion + Divide & Conquer + Symmetry Observation 🧩 Key Learnings: ● Never build exponential structures directly — reduce the problem. ● Recursive definitions often hide symmetry. ● The middle element becomes a powerful pivot. ● Mirroring + inversion patterns simplify complex generation problems. ● Think structurally, not sequentially. This problem reminded me that many recursive constructions are just cleverly disguised divide-and-conquer problems. 🔥 Day 85 complete — stronger recursion intuition and pattern recognition sharpening further. #LeetCode #100DaysOfCode #Java #Recursion #DivideAndConquer #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 95 of My 100 Days LeetCode Challenge | Java Today’s challenge was a grid traversal + simulation problem that required careful observation of patterns. The goal was to find the three largest rhombus border sums in a grid. Unlike regular submatrix problems, this one only considers the border elements of rhombus shapes, which makes the calculation a bit more tricky. The approach involved exploring each cell as a potential rhombus center, expanding possible rhombus sizes, and calculating the sum of the boundary elements while ensuring the rhombus stays within grid limits. A TreeSet helped efficiently keep track of the top three unique sums. ✅ Problem Solved: Get Biggest Three Rhombus Sums in a Grid ✔️ All test cases passed (117/117) ⏱️ Runtime: 217 ms 🧠 Approach: Grid Traversal + Simulation + TreeSet 🧩 Key Learnings: ● Grid problems often require careful boundary management. ● Visualizing shapes (like rhombuses) helps simplify implementation. ● TreeSet is useful for maintaining sorted unique values efficiently. ● Simulation-based solutions demand attention to detail. ● Not every grid problem is about rectangles — shapes matter too. This problem was a good reminder that geometric patterns in grids can lead to interesting algorithmic challenges. 🔥 Day 95 complete — improving my grid traversal and pattern-handling skills. #LeetCode #100DaysOfCode #Java #GridProblems #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
𝐈𝐧𝐡𝐞𝐫𝐢𝐭𝐚𝐧𝐜𝐞 gives hierarchy. 𝐏𝐨𝐥𝐲𝐦𝐨𝐫𝐩𝐡𝐢𝐬𝐦 gives flexibility. But 𝐚𝐛𝐬𝐭𝐫𝐚𝐜𝐭𝐢𝐨𝐧 gives clarity. Abstraction means: 𝗲𝘅𝗽𝗼𝘀𝗲 𝘄𝗵𝗮𝘁 𝗺𝗮𝘁𝘁𝗲𝗿𝘀, 𝗵𝗶𝗱𝗲 𝗵𝗼𝘄 𝗶𝘁 𝘄𝗼𝗿𝗸𝘀. In Java, this is done using abstract classes and methods. Example: abstract class Vehicle { abstract void start(); } Here, 𝐕𝐞𝐡𝐢𝐜𝐥𝐞 defines a rule: Every vehicle must know how to start. But it doesn’t define how. That responsibility moves to subclasses: class Car extends Vehicle { void start() { System.out.println("Car starting"); } } Now we’ve separated: • What must be done (contract) • How it is done (implementation) This improves design because: • Base classes define expectations • Subclasses provide behavior • Systems become easier to extend Today was about: • Understanding 𝐚𝐛𝐬𝐭𝐫𝐚𝐜𝐭 keyword • Designing base classes that define contracts • Separating behavior definition from behavior implementation Abstraction reduces noise. It lets you think at the right level. #Java #OOP #Abstraction #SoftwareDesign #CleanCode #LearningInPublic
To view or add a comment, sign in
-
-
From OOP to Functional Determinism: the last Java build before I go full JAX For years we’ve been sold the lullaby: “AI will solve everything.” But in real production (finance, energy, safety), the core pain is usually not “lack of intelligence”. It’s lack of repeatability. -Not “usually correct.” -Not “works on my machine.” -Not “cp,cpk 0.87.” Repeatable. Auditable. Deterministic. That’s why I’m building Vojker™ — Responsive/Deterministic-as-a-Service: a decision engine niche carved out intentionally in an “AI solves all” world. 🛳️ This week’s milestone: I shipped the Golden Run (Java reference engine). Golden Run is not a test suite — it’s a truth reference: Same input → same decision → same bytes. Always. What it does, deterministically: *Reads one canonical snapshot JSON (symbol, timeframe, OHLCV, timestamp, volume) *Computes a SHA-256 fingerprint (input DNA) Runs an ordered Guard Chain + FSM gates with explicit reason codes *Emits my favorite part: a deterministic AUDIT JSON *Compares output vs expected byte-for-byte (mismatch → FAIL, instantly) And the best part: it’s enforced by CI/CD. Every push/PR compiles + runs GO/NO_GO cases in GitHub Actions. If a single byte drifts, the build fails. 🏭 I see this as software poka-yoke, with deep, DEEP respect to W. Edwards Deming and Shigeo Shingo: build quality into the system so “number 7 today is number 7 tomorrow… and months from now.” Next: I’m moving full-time into Python + JAX (JIT + VMAP/SHMAP) for parallel compute — without ever breaking the Golden truth reference. GitHub: https://lnkd.in/dc2esewp 🦊 #VojkerRDaaS #determinism #quality #lean #jax #engineering #trading #bess
To view or add a comment, sign in
-
🚀 Day 3 – LeetCode Practice Today, I solved the 3Sum problem on LeetCode: 🎯 Difficulty: Medium/Hard 💻 Language Used: Java 💡 Approach: • Given an integer array nums, the objective was to find all unique triplets that sum up to zero. • I sorted the array first to simplify searching and avoid duplicates. • Used a fixed pointer + two-pointer technique: – For each element (as the first of the triplet), used two pointers to find pairs that complete the sum to zero. • To avoid duplicate triplets, I skipped repeated values during iteration. ⏱ Complexity: • Time Complexity: O(n²) • Space Complexity: O(1) (excluding output list) 📚 Key Takeaway: This problem strengthened my understanding of sorting combined with two-pointer strategies to reduce brute-force complexity. Handling duplicates correctly was also key to returning unique triplets. Consistent problem-solving practice continues to improve my algorithmic thinking and confidence in handling array-based challenges. 💪 #LeetCode #Java #DSA #TwoPointers #Arrays #ProblemSolving #Algorithms #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
This post https://lnkd.in/gfB7Rp8p documents a multi-phase refactoring of a compiler VM, done across a dozen sessions with an AI coding assistant. What started as a fix for Java string concatenation expanded into migrating every runtime value to carry its type: touching handler dispatch, return paths, heap storage, closures, and builtins. Each phase exposed assumptions the previous design had hidden. The post traces the full arc: the design decisions, the detours, and where I had to intervene.
To view or add a comment, sign in
-
Day 17/30 – LeetCode streak Today’s problem: Find Kth Bit in Nth Binary String (1545). 'S₁ = "0"', and 'Sₙ = Sₙ₋₁ + "1" + reverse(invert(Sₙ₋₁))'. Length of 'Sₙ' is always '2ⁿ - 1', with a '1' sitting exactly in the middle. The structure looks like this: Sₙ = [Sₙ₋₁] + '1' + reverse(invert(Sₙ₋₁)) So for any position 'k': - Let 'mid = 2^(n-1)' (the middle index, 1-based). - If 'k == mid', answer is '1'. - If 'k < mid', it’s in the left half, which is exactly 'Sₙ₋₁' → recurse: 'findKthBit(n-1, k)'. - If 'k > mid', it’s in 'reverse(invert(Sₙ₋₁))'. Mirror it back into 'Sₙ₋₁' at 'mirror = 2*mid - k' (same as '2ⁿ - k'), recursively get that bit from 'Sₙ₋₁', then flip it. Day 17 takeaway: This is one of those problems where drawing the recursive construction once (left + 1 + reversed/inverted left) makes the “mid / mirror / invert” recursion feel natural—and you never have to actually build the string. #leetcode #dsa #java #recursion #consistency
To view or add a comment, sign in
-
-
🚀 Day 11 of #50DaysLeetCode Challenge Today I tackled a HARD problem: “Regular Expression Matching” on LeetCode using Java. 🔹 Problem: Given a string "s" and a pattern "p", implement regex matching with support for: • "." → matches any single character • "*" → matches zero or more of the preceding element Return true if the entire string matches the pattern. Example: Input: "s = "aa", p = "a*"" → Output: "true" Input: "s = "aa", p = "a"" → Output: "false" 🔹 Approach I Used: I used Dynamic Programming (DP) — anything else here is inefficient or breaks on edge cases. ✔ Created a 2D DP table "dp[m+1][n+1]" ✔ "dp[i][j]" represents whether "s[0...i-1]" matches "p[0...j-1]" ✔ Handled "*" carefully: - Treat it as zero occurrence → "dp[i][j-2]" - Or one/more occurrence → match previous character ✔ Built the solution bottom-up 🔹 Concepts Practiced: • Dynamic Programming (2D DP) • String pattern matching • Handling complex edge cases #LeetCode #DSA #Java #DynamicProgramming #Algorithms #CodingChallenge #50DaysOfCode
To view or add a comment, sign in
-
-
🚀 𝗗𝗮𝘆 𝟴 𝗼𝗳 𝗺𝘆 𝗝𝗮𝘃𝗮 𝗷𝗼𝘂𝗿𝗻𝗲𝘆 ━━━━━━━━━━━━━━━━━━ 💡 𝗧𝗼𝗱𝗮𝘆’𝘀 𝗖𝗼𝗻𝗰𝗲𝗽𝘁: 𝗠𝗲𝘁𝗵𝗼𝗱 𝗢𝘃𝗲𝗿𝗿𝗶𝗱𝗶𝗻𝗴 ━━━━━━━━━━━━━━━━━━ In simple terms, method overriding happens when a child class provides its own version of a method that already exists in the parent class. What I understood today: → Same method name → Same parameters → Different implementation → Happens through inheritance This is how runtime polymorphism works in Java. Using @Override made the code cleaner and safer. It feels powerful to see how Java decides which method to execute at runtime. Not just coding. Understanding structure. Understanding behavior. Understanding OOP deeply. 💻✨ #Java #OOP #overriding #Day8 #LearningInPublic
To view or add a comment, sign in
-
-
🚀 𝗣𝗼𝗹𝘆𝗴𝗹𝗼𝘁 𝗔𝗱𝗮𝗽𝘁𝗲𝗿 → 𝗣𝗼𝗹𝘆𝗴𝗹𝗼𝘁 𝗣𝗹𝗮𝘁𝗳𝗼𝗿𝗺 What started as a runtime abstraction has evolved into a modular polyglot ecosystem. 𝗥𝘂𝗻𝘁𝗶𝗺𝗲: – GraalVM context management – Python / JS inside JVM – Spring Boot integration 𝗧𝗼𝗼𝗹𝗶𝗻𝗴: – Contract-based model – Deterministic Java interface generation – Maven plugin for build-time code generation The goal is simple: Make polyglot integration inside JVM applications structured and production-ready — 𝘄𝗶𝘁𝗵𝗼𝘂𝘁 𝗶𝗻𝘁𝗿𝗼𝗱𝘂𝗰𝗶𝗻𝗴 𝗮𝗱𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹 𝗻𝗲𝘁𝘄𝗼𝗿𝗸 𝗯𝗼𝘂𝗻𝗱𝗮𝗿𝗶𝗲𝘀, 𝗥𝗣𝗖 𝗹𝗮𝘆𝗲𝗿𝘀, 𝗼𝗿 𝗺𝗶𝗰𝗿𝗼𝘀𝗲𝗿𝘃𝗶𝗰𝗲𝘀. The video below shows: 𝗣𝘆𝘁𝗵𝗼𝗻 𝗶𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻 → 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗲𝗱 𝗝𝗮𝘃𝗮 𝗶𝗻𝘁𝗲𝗿𝗳𝗮𝗰𝗲 → 𝗗𝗶𝗿𝗲𝗰𝘁 𝗝𝗩𝗠 𝗲𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻. Documentation is being expanded with architecture details and usage examples. Feedback is welcome.
To view or add a comment, sign in
Explore related topics
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