- 1
how to avoid overloading in java ?
2 Antworten
+ 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
+ 1
Depend on what you re writing BTW where is the code