what is the use of public static void and how it changes when we use addition subtraction ???
Doubt in function demo
public
means that the method is visible and can be called from other objects of other types. Other alternatives are private
, protected
, package
and package-private
.
static
means that the method is associated with the class, not a specific instance (object) of that class. This means that you can call a static method without creating an object of the class.
void
means that the method has no return value. If the method returned an int
you would write int
instead of void
.
The addition and subtraction are just names of the functions that we are creating. Addition function will add 2 variables and print the sum. Subtraction function will subtract 2 variables and print the difference