3

This is my first week of Java and I am wondering how to set default parameters for a method or constructor.

For example, in Python, it'd look like this: def test_function(a=None, b, c=1):

Is there any way to do that in Java?

0

1 Answer 1

10

You would have to overload that function with no arguments, and call it internally with 'defaults'

public void sayHello(){
   sayHello("Stranger");
}

public void sayHello(String name){
   System.out.println("Hello "+name);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.