wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method overloading vs method overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method overloading vs method overriding" Watch "method overloading vs method overriding" New topic
Author

method overloading vs method overriding

HiteshKumar Singh
Greenhorn

Joined: Apr 15, 2013
Posts: 4
why return type is not considered in method overloading whereas it is considered in method overriding?
Ramesh Pramuditha Rathnayake
Ranch Hand

Joined: Oct 31, 2012
Posts: 175
    
    1

Return type is considered in overloading too...


Ramesh-X
HiteshKumar Singh
Greenhorn

Joined: Apr 15, 2013
Posts: 4
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

Joined: Jul 09, 2001
Posts: 1180
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


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Ramesh Pramuditha Rathnayake
Ranch Hand

Joined: Oct 31, 2012
Posts: 175
    
    1

They are not overloaded.. They give a compile error..!!
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Right, it says -



Regards,
Dan
HiteshKumar Singh
Greenhorn

Joined: Apr 15, 2013
Posts: 4
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

Joined: Oct 31, 2012
Posts: 175
    
    1

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

Joined: Apr 15, 2013
Posts: 4
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

Joined: Dec 25, 2012
Posts: 82
    
    1

Dan Drillich,thank you for the link it was very useful
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method overloading vs method overriding