• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Most specific Method-Overloading??

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

I tried the code below,



And it gave me short short boolean as the o/p. From the definition of the most specific method, it is one in which the arguments that we pass can be passed to the other methods without a compile time error. Now in the above case, anything that can be passed to a short cannot be passed to a byte, so shouldn't it give a compile time error??
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

1. short b1;
2. m1(b1 = 1);
3. m1(b1);
4. m1(b1 == 1);

in line 2. b1 is assigned 1, so b1 is a short with a value of 1.
in line 3. you call m1() with a short again, so it calls m1(short s1) and prints "short".
The point is, b1 doesn't become a byte in that code.

Did I get your problem right?

Ciao,
Tommaso
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i guess this is the most basic case of methode overloading , if you are passing specificaly a "short" type of variable you would expect
"static void m1(short s1)" function to be called and not a function that takes a byte or a integer parameter , of course would there have been no any m1(short s1) kind of function then static void m1(int i1) might be called.

I hope i have understood the question correctly.
 
Won't you be my neighbor? - Fred Rogers. tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic