+ 1
Write a code in java for (function and constructor overloading) that should elaborate the concept.How they are created and used.
Complete question is here What do we mean by function and constructor overloading. Write a piece of code in java for each of them that should elaborate the concept.(How they are created and used).
5 Réponses
+ 1
I'll explain what it means by overloading a function (since constructor is just another type of function/method)
Basically, it is defining two or more functions with sane name but different argument, for example:
public double square(int num1, int num2)
public double square(double num1, double num2)
public double square(int num1)
So as you can see, the return type must be the same, but the number of arguments and type of arguments can be changed.
0
Normally it is used when you want your function to be able to handle different data types, like the square above, you mught want to implement for all number types
0
Hoh Shen Yien
Method overloading and function overloading is name thing?
0
Yes, functions are technically methods in java
0
Thanks ❤️