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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With