can't i give parameters in calling function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can't i give parameters in calling function

for ex- class myclass{ static void sayhello(){ system.out.println("hello"); } public static voidmain(string[ ] args){ say hello(); } } if i give - static void sayhello( string[ ] a) after class then why it is wrong.

4th Nov 2016, 5:06 AM
Abhishek Gurani
Abhishek Gurani - avatar
2 Answers
+ 1
argsĀ contains the command-line arguments passed to the Java program upon invocation. For example, if I invoke the program like so: $ java MyProg -f file.txt ThenĀ argsĀ will be an array containing the stringsĀ "-f"Ā andĀ "file.txt". IT is mainly used when you pass arguments to program befote execution. In your program you have to send argument to function sayhello. Otherwise it show error. Remember you can only send command line argument to main thats why it generate error when you did not pass argument to sayhello function.
4th Nov 2016, 5:48 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
@Aditya thank u for ur revert but can u tell.me the errors and pleas cn u briefly explain. as i am a begineer and this is the same program i have seen in calling method chapter of this app
4th Nov 2016, 5:20 AM
Abhishek Gurani
Abhishek Gurani - avatar