Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading concept

 
Mateus Brigido
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I'm new here. I'm studying for the OCAJP and this question came into my mind.

The code below show to classes C1 and C2, both of them have m1 method.

I know that this is not overriding because the methods have different signatures.
The questions is, could this be considered overloading, or only occurs with methods of the same class?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mateus Brigido wrote:
The questions is, could this be considered overloading, or only occurs with methods of the same class?

No, ideally overloading applies only to the same class but it would not be far fetched to apply the concept to a non-private method in a derived class as well because the derived class does inherit such methods.
Definitely not for different unrelated classes.
 
Mateus Brigido
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Anilprem wrote:
No, ideally overloading applies only to the same class but it would not be far fetched to apply the concept to a non-private method in a derived class as well because the derived class does inherit such methods.
Definitely not for different unrelated classes.


Thanks Paul
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI, as per JLS 7 section 8.4.9., as I suspected, overloading applies to inherited methods as well:

If two methods of a class (whether both declared in the same class, or both inherited by a class, or one declared and one inherited) have the same name but signatures that are not override-equivalent, then the method name is said to be overloaded.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic