What is method ambiguity in Java.




package Java8;

public class Overloading {
     
public static void main(String[] args) {
      // TODO Auto-generated method stub
     //m1( null);  error  Method  m1()  is  ambiguous  for  this  this value.
   
         OverloadingA.m1(17);
        OverloadingB.test( 10) ;
          //OverloadC.test(null);   error   Method  test  is ambiguous  Due to  test(Integer g)
               OverloadC.test("String");
 
                    }

}



   class   OverloadingA{


              public  static void  m1( String s) {
 
                   System.out.println( s);
 
                     }
                 public  static  void  m1( Integer  s
           {
 
             System.out.println( s);
 
        }
}
   
class    OverloadingB{

   public  static void test(long lng)
   {
         System.out.println("Long");
   
     }
 
    public static  void test(Integer integer) {
          System.out.println("Integer");
          }
    }


   class    OverloadC {
               public static void test(String str) {
 
             System.out.println("String");
         }
      public  static void test(Object obj) {
 
        System.out.println("Object");
   
      }
      public static  void test(Integer integer) {
      System.out.println("Integer");
    }


}


What is method ambiguity in Java. What   is  method    ambiguity   in Java. Reviewed by Mukesh Jha on 8:45 PM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.