Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method overloading vs method overriding

 
HiteshKumar Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why return type is not considered in method overloading whereas it is considered in method overriding?
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Return type is considered in overloading too...
 
HiteshKumar Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh Pramuditha Rathnayake wrote:Return type is considered in overloading too...

hi Ramesh,
i have 2 methods,
void abc(int a){}
int abc(int a){}
are they overloaded?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Method Overloading (function overloading) in Java says -

The fact that the fourth version of test( ) also returns a value is of no consequence relative to overloading, since return types do not play a role in overload resolution.


Regards,
Dan
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are not overloaded.. They give a compile error..!!
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, it says -



Regards,
Dan
 
HiteshKumar Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh Pramuditha Rathnayake wrote:They are not overloaded.. They give a compile error..!!

but in your previous post you mentioned that return type too are considered in overloading.
kindly elaborate with an example.
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a problem with my english knowledge..!

I want to say was, if return type is different though method signature is equal, compile error gives..
No mater whether you are going to override or overload..!
 
HiteshKumar Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh Pramuditha Rathnayake wrote:That's a problem with my english knowledge..!

I want to say was, if return type is different though method signature is equal, compile error gives..
No mater whether you are going to override or overload..!

ok sir, i got it. thank you!
 
Gajendra Kangokar
Ranch Hand
Posts: 94
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Drillich,thank you for the link it was very useful
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic