Saturday, 18 July 2015

Call method using null param!


public class TestClass1 {
       public static void main(String[] args) {
              show(null); // The method show(String) is ambiguous for the type TestClass1
       }

       private static void show(String str) {
              System.out.println("String str");
       }
      
       private static void show(int[] str) {
              System.out.println("int[] str");
       }
}

-----------------------------------------------------------------------------------------
public class TestClass1 {
       public static void main(String[] args) {
              show(null);
       }

       private static void show(String str) {
              System.out.println("String str");
       }
      
       private static void show(Object str) {
              System.out.println("int[] str");
       }
}

Output : Strinstr

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...