• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Top Urgent

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,
I got this code from some mock exam cant remeber the name
Code -->
---------
class q20
{
public static void main(String[] args)
{
System.out.println("Hello World!");
q20 qq = new q20();
qq.callme(7l,7l,7l);
}
void callme(double d, float f, long i){
System.out.println("One");
}
void callme(float ff, double dd , long ll){
System.out.println("Two");
}
void callme(int ff, int dd , int ll){
System.out.println("Three");
}
}
After compilation-->
----------------
q20.java:7: Reference to callme is ambiguous.
It is defined in void callme(double, float, long)
and void callme(float, double, long).
Can anyon explain me why is the problem
Yogesh
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi yogesh
qq.callme(7l,7l,7l);
7l or 7L is of type Long, so
void callme(int ff, int dd , int ll) gets ignored.
converting a Long to Float is not considered a narrowing conversion so it can be done without cast.
so the compiler doesn't know which method
void callme(double d, float f, long i){}
or
void callme(float ff, double dd , long ll){}
to call because both are legal to be called with
qq.callme(7l,7l,7l);
so it is ambiguous
hope that helps
 
reply
    Bookmark Topic Watch Topic
  • New Topic