• 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

Overloading ambiguity

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
When I compile the below code, I get ambiguity error because the compiler cannot make out which overloaded version of the method is being called. However, this ambiguity does not happen between the superclass versions of overloaded methods, if I instantiate the superclass instead of the subclass.
Whats the reason ?
class Tester
{
public int func(int x, int y){
return x+y;
}
public long func(long x, long y){
return x*y;
}
}
class NewTester extends Tester
{
public long func(long x, long y){
return (x/y); }
}
class Test
{
public static void main(String args[])
{
NewTester t=new NewTester();
//Tester t=new Tester();
System.out.println(t.func(1,2));
}
}
Thanks
Deepti
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic