• Post Reply Bookmark Topic Watch Topic
  • New Topic

what should be the output and why?  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi Tim,

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


Answer for Why..I am not sure …


 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • 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
  • 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: 56600
172
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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: 56600
172
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!