• 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

what should be the output and why?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 5554
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you run the program and tell us what the output is?

Then if there's something about the output you got that you don't understand then come back with your questions.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

It is "…".. statement from show(…) method...


Answer for Why..I am not sure …


 
Marshal
Posts: 79054
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please note what it says on the title page of this forum

We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.

It does not help the OP to be told the answer like that; it reduces the educational value of the discussion. Please don't be annoyed, but I have pulled rank and removed part of your pots.
It might be worth reading about overloading in the Java Language Specification, but it is by no means easy to read. You may need to go on to ยง15.12.2.
 
amod gole
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell,

thanks for helping me and sorry for my reply..that was my reply after 4 years...I have started Java again
 
Campbell Ritchie
Marshal
Posts: 79054
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's give MAK a bit longer to reply, then I shall let you out of your misery.

And apology accepted
 
Ranch Hand
Posts: 38
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The output will be 'object array' it will always give precedence to array argument method, if it is not present the output will be 'object'.
 
Campbell Ritchie
Marshal
Posts: 79054
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that is not correct.

In a case of overloading, the compiler chooses the method whose parameter type is more specific. A null might be an Object or an array of Objects. An array of Objects is more specific; an array of Objects is an Object but an Object is (usually) not an array of objects. So Object[] is more specific and that is chosen by preference.
This shows a pitfall of overloading; it is not obvious to the reader which method is chosen.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic