There are 2 methods called min - so how does main know which one to use for the final output? Is it the order they are written?
Its confusing that there can be 2 methods of the same name.
Finished task - but need clarification on something.
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
amaral
3 October 2018, 18:37
differenciate method acoording to no. of argument, or their type, main decide final output acoording to no. of input
0
Ankush Rajput
2 October 2018, 11:14useful
Difference is in the arguments. If min(1,2,3,4) is called, min with four parameters will be called. And if min(1,2) is called, min with two parameters will be called.
You can create as many functions as you like with same name, but arguments should be different.
Even type difference is sufficient or order difference is sufficient.
For example -
function(int a,String b); function(int a, int b); function(String b,int a) all are valid functions and can exist together.
It is called method/function overloading. You'll learn in later levels.
+3
WatWat
5 October 2018, 09:07
Ah thank you, very helpful Ankush :)
0