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.
2 Réponses
+ 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.
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