0

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?

Shlok Sharma
  • 108
  • 1
  • 5

1 Answers1

3

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);
}
Antoniossss
  • 28,922
  • 5
  • 49
  • 91