0
[DUPLICATE] What is "args" ?..
I understand a string is a sequence of characters to create a variable or value or object, but what is the "args" and why is it essential?.. (Side question) - Void, I understand this "Does not return any value" but what does that mean? it sends a value to an object but does not return anything to the console? So in other words renders the command or function useless?.. Sorry if my terminology makes things confusing, I am still trying to grasp all this at the moment and I guess it is a little difficu
4 Answers
+ 6
args is just the name of the array. Call it whatever. args is default because it stands for arguments.
void does not return anything, so a void function is generally focused on doing some sort of 'commands'.
ex/
void print(String msg){
System.out.println(msg);
}
I can call this function to print a msg, but I cannot expect to receive any value from the function. It is only designed to print a message.
Note*
You can say:
"return;"
in a void function. This will simply terminate/end it. There cannot be anything to return though.
+ 5
Yes if you don't know what a returned function is, don't worry about it. But here's some incite anyway.
When I receive a value from a function I can basically use the function as a value. Here's an example.
int sum = findSum(3, 2);
System.out.println(sum);
int findSum(int a, int b){
return a+b;
}
Output: 5
findSum() returns the sum of the arguments. That means that when I call the function I will receive whatever is returned as the value of the function. In this case, the sum of the arguments.
sum = findSum(3, 2) + 1;
Will output 6.
Breakdown:
findSum(3, 2) = 5.
sum = 5 + 1;
sum = 6.
Or you could just do:
System.out.println(findSum(3, 2));
Output: 5
Returning sounds vague but that's exactly what it does. Hopefully the examples make it easier to understand.
+ 1
Definatly helps me understand a lot more! I seriously appreciate the help. I'll keep rolling these courses out though for sure! :P
0
Thank you! it's still a little vague when you say, you can't expect to receive any value from the function, by this you mean what?.. or should I not even be worried / focused on that yet? I don't know what a function with a returned value even is yet so I suppose stay tuned and just keep faith? lol but again thank you for the explanation!