• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overloading  RSS feed

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have following example

Given the following class definition, which of the following methods could be legally placed after the comment

1)public void amethod(String s, int i){}
2)public int amethod(int i, String s){}
3)public void amethod(int i, String mystring){}
4) public void Amethod(int i, String s) {}

Answer should be 1 , 2. 1 has parameters altered, which makes it different from one in class (I dont understand what different does it make though) and 2 has different type so its different from one in class.
Answer is 1 and 4. So is amethod() and Amethod() are two different methods ?

Thanks
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess there is a source where this came from?

Two methods must have different signatures to be distinct. The return type is NOT part of the signature. So 2 can't be placed in the class as it is identical to the existing method in the properties used for distinction.

Java is case sensitive.
 
Mohamed Sanaulla
Bartender
Posts: 3179
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!