+ 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).

15th Apr 2021, 9:39 AM
Haider Ali Waris
Haider Ali Waris - avatar
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.
15th Apr 2021, 10:11 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
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
15th Apr 2021, 10:13 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
0
Hoh Shen Yien Method overloading and function overloading is name thing?
15th Apr 2021, 10:16 AM
Haider Ali Waris
Haider Ali Waris - avatar
0
Yes, functions are technically methods in java
15th Apr 2021, 10:17 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
0
Thanks ❤️
15th Apr 2021, 10:17 AM
Haider Ali Waris
Haider Ali Waris - avatar