Default method variables Python vs. Java

In Java you have to set default method values at either

1) A global level (Not safe)

2)Each time the method is called before you do any work within the method. This is preferred but involves a couple extra lines of code

In Python, you can set default values in the definition of the function itself. If a value is passed in, it overrides the default, if not, the default value is used.

def someMethod (self, var1, var2, var3=’false’):

In this example, var3 will always be set to ‘false’  (and you don’t need to pass it), but if you do pass it in, var3 will take on the passed in variables value.

In java it would be more like this:

void someMethod ( String var1, String var2, String var3){

String local_var1 = var1;

String local_var2 = var2;

String local_var3 = “false”;

local_var3 = var3;


You have to define the default value and then overwrite it.