Results 1 to 4 of 4
  1. #1
    Anveshan is offline Member
    Join Date
    May 2011
    Posts
    24
    Rep Power
    0

    Default Need clarification..New to java

    I have overloaded a method (here it is "testMethod") with one version talking String as argument and another taking as Object. Now when I invoke testMethod() with null as parametre, the one with String argument is called. Can anyone explain why "testMethod(String s)" instead of "testMethod(Object s)" ? (null doesn't pass instance of test with string)

    public static void main(String[] args)
    {
    testMethod(null);
    }

    static void testMethod(String s)
    {
    System.out.println("this is string");
    }
    static void testMethod(Object s)
    {
    System.out.println("this is object");
    }

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    There was a good discussion over velocityreviews about the same. That will help you out. Read it fully here : difference between null object and null string

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    Quote Originally Posted by goldest View Post
    There was a good discussion over velocityreviews about the same.
    Yup Thanks for sharing it.

    db

  4. #4
    Anveshan is offline Member
    Join Date
    May 2011
    Posts
    24
    Rep Power
    0

    Default Re: Need clarification..New to java

    Thanks for sharing the discussion over velocityreviews ..is been very helpful

Similar Threads

  1. Clarification on main method
    By Hype in forum Advanced Java
    Replies: 5
    Last Post: 02-17-2011, 06:49 AM
  2. Struts Clarification
    By vinothkumarrvk in forum Web Frameworks
    Replies: 0
    Last Post: 02-26-2010, 02:24 PM
  3. need clarification in this statement.
    By Unsub in forum New To Java
    Replies: 5
    Last Post: 02-26-2010, 01:16 PM
  4. HELP! need clarification
    By ptsofathrty in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 08:02 AM
  5. Private Classes Clarification
    By justlearning in forum New To Java
    Replies: 1
    Last Post: 05-06-2008, 10:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •