• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to understand the output.  RSS feed

 
Khuzema Dharwala
Ranch Hand
Posts: 61
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks,

I have following code




I just wanted to know why it is giving output as "String".

Any help in this matter is highly appreciated.

Thanks...
 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I understand is, Java static method resolved at compile time.
And since the method is overloaded, it will try to call the most specific one, which is the String one.

The following code would print "Object" instead


If you have another overloaded method (e.g. Integer), it would have compile error. Because it can not determine which method is most specific.
 
Khuzema Dharwala
Ranch Hand
Posts: 61
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raymond for your nice explanation.
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I'm looking at the wrong thing, but it's printing "String" because that is what you have told it to print.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!