+3

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

9/12/2019 7:29:45 PM

Eliya Ben Baruch

10 Answers

New Answer

+3

It is not possible in java.

+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

+2

מאיפה אתה בארץ?

+2

No it doesn't really help me but thanks anyway

+1

Thanks KfirWe

+1

Eliya Ben Baruch בכיף גבר

+1

Yeah I know about it Denise Roßberg I just was wondering about this

+1

KfirWe טוב לראות מישהו מישראל

+1

תותח

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