how to avoid overloading in java ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

how to avoid overloading in java ?

19th Feb 2021, 9:17 AM
Muluken Mnyahl
Muluken Mnyahl - avatar
2 Answers
+ 2
Why would you want to avoid overloading? That makes no sense to me. It is one of the 2 principles of implementing Polymorphism. Suppose you have a function that calculates the area of a square and accepts an integer. Now suppose you want to use the same function to calculate the area of a circle. If you pass a floating point value to the function it'll throw an error as you declared it to accept integers. This is where Overloading steps in. You declare the same function twice with different arguments and occasionally different return type. This way you don't need to write multiple functions
20th Feb 2021, 1:46 PM
Soumik
Soumik - avatar
+ 1
Depend on what you re writing BTW where is the code
19th Feb 2021, 9:46 AM
Ananiya Jemberu
Ananiya Jemberu - avatar