+ 4

Is it possible to have default values for parameters in Java?

12th Sep 2019, 7:29 PM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
10 Answers
+ 3
It is not possible in java.
12th Sep 2019, 7:47 PM
KfirWe
KfirWe - avatar
+ 3
No it doesn't really help me but thanks anyway
13th Sep 2019, 7:30 AM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
+ 2
Eliya Ben Baruch You can overload your method. For example: public void myMethod (){ //using default values } public void myMethod (int i){ //using the given int i } https://www.sololearn.com/learn/Java/2165/?ref=app
12th Sep 2019, 8:41 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
מאיפה אתה בארץ?
12th Sep 2019, 9:03 PM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
+ 1
Thanks KfirWe
12th Sep 2019, 8:02 PM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
+ 1
Eliya Ben Baruch בכיף גבר
12th Sep 2019, 8:57 PM
KfirWe
KfirWe - avatar
+ 1
Yeah I know about it Denise Roßberg I just was wondering about this
12th Sep 2019, 8:58 PM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
+ 1
KfirWe טוב לראות מישהו מישראל
12th Sep 2019, 9:02 PM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
+ 1
תותח
14th Sep 2019, 2:32 PM
King4242
King4242 - avatar
0
Eliya Ben Baruch Maybe there is another way if you use objects as parameters: if parameter = null -> use default value else use parameter Here is a small example using String: https://code.sololearn.com/cPB4aFC9t11o/?ref=app
12th Sep 2019, 9:30 PM
Denise Roßberg
Denise Roßberg - avatar