Results 1 to 4 of 4
  1. #1
    jibhekar is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default help me for this

    Which overloaded version program will excuted............

    class MyClass{
    public void myFun(Object o){

    System.out.println("Object version executed");
    }
    public void myFun(String s){

    System.out.println("String version executed");
    }

    public static void main(String args[]){

    MyClass obj = new MyClass();
    obj.myFun(null);

    }

    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    String version executed.

    First think about default values. In both overloaded methods, you are referencing objects(s also an object of String class, not like primitives.) Default values not referring any objects.

    So, think about class hierarchy. Object class is the root/main of the class hierarchy. That means every class has Object as superclass. String class also extended Object. That's why you got the above result I mentioned.

    Try to remove that overloaded method, second method with argument type String. You get the result as, Object version executed

    Hope it's help to you.

  3. #3
    jibhekar is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default

    thanks
    i got it thanks so much

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Posting Permissions

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