+ 1
does optional arguments considered as overloading the method ?
1 Answer
0
No.
Function overloading
two or more methods with same name and different number of parameters, data types.We are look at the method signature.
int sum(int a, int b)
int sum(int a, int b, int c)
Optional parameter
int add(int a, int b=1)
but if u try below with the above 'add' function.
int add(int a, int b)
compiler gives some error:
"already defines a member called 'sum' with the same parameter types"