+ 1
How set default value to method paramenter in java
2 Respuestas
+ 1
Java (unlike C++) does not allow for default values. You can, on the other hand, overload the method with less arguments. For example, create a method:
int add(int x, int y) {
return x + y;
}
// now, the 'default' value:
int add(int x) {
return add(x, 1); // in this case, '1' looks like the value
}
Basically, we are just redefining the method, except with less arguments. The new method just passes the default value to the method.
+ 1
thank you very much ...