why are there two different running results for the two piece of code?
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);
}
}
Answers
The code does not compile.
The code compiles cleanly and shows "Object Version".
The code compiles cleanly and shows "String Version"
The code throws an Exception at Runtime.
the ans is 3rd.
i thought if the code were written like 'questin.method("null")', the ans were 3rd, but .... i dont know why?
----------
Question 124)
Read the code below. Will be the result of attempting to compile and run the code below.
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);
}
}
Answers
The code does not compile.
The code compiles cleanly and shows "StringBuffer Version".
The code compiles cleanly and shows "String Version"
The code throws an Exception at Runtime.
the ans is first one. why? only because of "public void method(StringBuffer sb)?"