First consider the below example :
public class AQuestion
{
public void method(Object o)
{
System.out.println("Object Verion");
}
public void method(
String s)
{
System.out.println("String Version");
}
public static void main(String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}
}
Output: The code compiles cleanly and shows "String Version"
Now consider the below example :
public class AQuestion
{
public void method(StringBuffer sb)
{
System.out.println("StringBuffer Verion");
}
public void method(String s)
{
System.out.println("String Version");
}
public static void main(String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}
}
Output : The code does not compile.
Why is it so ?