+ 2
Is that mandatory to write the data type of parameter inside the parenthesis of a method? Can we declare it anywhere else?
class MyClass { static void sayHello(String name) { System.out.println("Hello " + name); } public static void main(String[ ] args) { sayHello("David"); sayHello("Amy"); } }
1 Answer
+ 2
yes it is mandatory.. because when u write the variables in parenthesis then it is a local variable created that can be used only within the method.. so the type of variable should also be known..
but while calling the method the data type is not required