What is the explanation of this java code ?

Posted by M.H on Stack Overflow See other posts from Stack Overflow or by M.H
Published on 2010-06-13T19:34:57Z Indexed on 2010/06/13 19:42 UTC
Read the original article Hit count: 112

Filed under:

I have the following code :

public class Main {
     public void method(Object o)
     {
           System.out.println("Object Version");
     }
     public void method(String s)
     {
          System.out.println("String Version");
     }
     public static void main(String args[])
     {
           Main question = new Main();
           question.method(null);//1
     }
}

why is the result is "String Version" ? and why there is a compiler error if the first method takes a StringBuffer object ?

© Stack Overflow or respective owner

Related posts about java