Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8766957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:40:56+00:00 2026-06-13T16:40:56+00:00

Possible Duplicate: Overloaded method selection based on the parameter’s real type How is an

  • 0

Possible Duplicate:
Overloaded method selection based on the parameter’s real type
How is an overloaded method choosen when a parameter is the literal null value?

When I execute the code below, I get the following output:

Method with String argument Called …”

Why?

public class StringObjectPOC {

    public static void test(Object o)   {
        System.out.println("Method with Object argument Called ...");
    }
    public static void test(String str){
        System.out.println("Method with String argument Called ...");
    }
    public static void main(String[] args) {
        StringObjectPOC.test(null);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:40:57+00:00Added an answer on June 13, 2026 at 4:40 pm

    I tried this:

    Test2.class

    public class Test2{}
    

    Test3.class

    public class Test3 extends Test2{
    
    }
    

    Test.class

    public class Test{
    
    public static void print(Object obj){
        System.out.println("Object");
    }
    
    public static void print(Test2 obj){
        System.out.println("test 2");
    }
    
    public static void print(Test3 obj){
        System.out.println("Test 3");
    }
    
    
    public static void main(String[]args){
        Test.print(null);
    }
    
    }
    

    it printed out Test 3

    Just like in your scenario, this means that if a method is overloaded (and when null is passed), it recognizes the method which has the child-most parameter.

    Object->Test->Test2
    

    or in your case:

    Object->String
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C#: Passing null to overloaded method - which method is called? Here
Possible Duplicate: C#: Passing null to overloaded method - which method is called? Consider
Possible Duplicate: unresolved overloaded function type c++ Consider the code snippet below: #include <algorithm>
Possible Duplicate: C# okay with comparing value types to null Why value type as
Possible Duplicate: The best overloaded method match for 'XDevkit.IXboxDebugTarget.GetMemory(uint, uint, byte[], out uint)' has
Possible Duplicate: method overloading vs optional parameter in C# 4.0 It seems as though
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Is it allowed to name the parameter in postfix operator ++? I
Possible Duplicate: Really impossible to use return type overloading? Is there a way to
Possible Duplicate: Overloading member methods with typedef aliases as parameters I have following method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.