+ 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"); } }

19th Jun 2017, 2:10 PM
Rose
Rose - avatar
1 Réponse
+ 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
19th Jun 2017, 3:14 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar