0
What's the difference between optional and required parameters?
Can you give examples of what these are and possibly explain simply for a beginner...
2 ответов
+ 3
public int add(int req, int def = 20) {
return req + def;
}
int a = add(10);
int b = add(10, 20);
int c = add(0, 30);
In this example: a, b and c are all equal to 30. Default values simply allow you to exclude them when you make a call to the function.
0
Thanks John. I'm noticing different people using different terms to explain the same thing. Your use of "default" makes more sense than "optional" or "required", whichever is meant to be.