Java Method Overloading Trick: What's the Output?

🚀 Day 4 — The Java Trick That Even Seniors Miss! 😮 Every Java dev thinks they understand method overloading... But this one small detail breaks their confidence 👇 public class OverloadTest { void show(Object o) { System.out.println("Object"); } void show(String s) { System.out.println("String"); } public static void main(String[] args) { OverloadTest test = new OverloadTest(); test.show(null); } } 🧠 Question: What will be the output of this code? Will it print: 1️⃣ Object 2️⃣ String 3️⃣ Compile-time error Most developers get this wrong! 😅 💬 Drop your answer in the comments 👇 Let's see how many of you actually know how Java resolves overloaded methods at compile time! #Java #CodingChallenges #SpringBoot #JavaDevelopers #InterviewQuestion #Day4Challenges #cbfr

The compiler chooses the one with the most specific parameter type. So the output will be String.

When multiple overloaded methods match, it selects the most specific type. output will be : String

See more comments

To view or add a comment, sign in

Explore content categories