- 1
how create overload method in java?
two method with same name but different parameters
2 Réponses
+ 4
Hello Abdulkedir Dube
You can have a look into my code:
https://code.sololearn.com/cggcHjdL0HEE/?ref=app
You can ask me if you need more explanation :)
+ 4
Overloading is the way to use same method name instead of having different names for different operations.For example in Java you have a method called abs() that you can pass different datatypes you need
Like
Math.abs(-15);// 15
Math.abs(-15.0);// 15.0
Unlikely in c you need to create different functions for different operations.
In c you need abs() for int and fabs() for floating points decimals.
This will make the code harder to maintain.So Java comes with feature called overloading.Tahat can achieve by different ways like
Using different types of parameters,using parameters or no parameter, parameters placings etc.