My First Post

Hi frnds I know the name of community is new to java. but i feel posts are real good ones. anyways I want to put a small question I'm sure many of u will be able to answer this question... Thx in advance

public class AQuestion

{

public void method(Object o)

{

System.out.println("Object Verion");

}

public void method(int s)

{

System.out.println("Integer Version");

}

public void method(StringBuffer s)

{

System.out.println("String Buffer Version");

}

public static void main(String args[])

{

AQuestion question = new AQuestion();

question.method(null);

}

}

why is that output is coming out to be String Buffer Version and not Integer Version or Object Version. Why Prefernce is given to StringBuffer(although StringBuffer or String is wrapper class)..

thx again

[927 byte] By [Jitu-javaa] at [2007-11-27 10:53:53]
# 1

int is not a possibility, since int can't be null.

The reason SB is chosen over Object is that SB is more specific. When an argument can work in more than one method, it uses the one that's the most specific (furthest from Object).

jverda at 2007-7-29 11:46:49 > top of Java-index,Java Essentials,New To Java...