user defined methods as variable input

Hello everyone.

I'm reading through a teach yourself java programming guide and am a little confused about a couple things when it comes to variables and methods.

I was wondering if it is "legal" to use a method as a variable input. Ex:

variable = usermethod(num1, 23.43, 32.13); /* Assuming the variable and method parameters

are of the same data type */

I was also wondering if you can call a method as output to the stand output such as:

System.out.println(usermethod(num1, 23.43, 32.13));

I think that these are vaild uses but this book is not very clear on this point, it simply says that a user defined method is called from the method main and if it is a return type it will return a value. I assume that the returned value can be store in a variable using the syntax above, am I correct?

[846 byte] By [jacksw02a] at [2007-11-26 18:49:38]
# 1
Both of those are valid if used correctly.
CaptainMorgan08a at 2007-7-9 6:23:39 > top of Java-index,Java Essentials,New To Java...
# 2

Whenever the compiler sees a method name, it calls the method to get a return value from it. Both of those lines above are legal.

You can use a method call pretty much anywhere you would put an expression; for example, if you had a function foo() which took an int, and you had another function bar() which returned an int, you could call foo() like this:

foo(bar());

Just make sure that methods you pass to other methods don't result in any unintended side-effects, such as printing to the screen.

JimmyMa at 2007-7-9 6:23:39 > top of Java-index,Java Essentials,New To Java...
# 3
This was very helpful. Sometimes you can over analyze something and you confuse yourself. Thank you for clarifying.
jacksw02a at 2007-7-9 6:23:39 > top of Java-index,Java Essentials,New To Java...