Click to See Complete Forum and Search --> : Passing Receiving?


Zarathustra22
12-21-2007, 04:54 PM
Hey guys,
I'm new to Java and I've heard a lot about passing and receiving, especially passing and receiving through methods. I'm curious, exactly what does this mean, and why is it of such fundamental importance?

chazzy
12-25-2007, 09:05 PM
I'm not new to java and I can be honest with you - I've never heard the term "passing and receiving." In fact, a quick google search returns a lot of results about soccer and hockey.

reggaeton_king
12-28-2007, 12:25 PM
I think you mean passing parameters to a method.

Here's an example. Say you write a method to calculate a number to the power of some number. You pass two numbers in the method. One is the base number, the other is the exponent. The return value is dependent on the passing values. See the code below.


public int power(int x, int n) //<--my passing values
{
if(n < 0) return 0;

int result = 1;
for(int i = 0; i < n; i++)
{
result = result * x;
}

return result; //<-- the return value
}

So, if you say power(5, 3), it will return 125. 5^3 = 125.

Make sense?