Java Class 7
Java Class 7
Note that when you are working with multiple parameters, the
method call must have the same number of arguments as there
are parameters, and the arguments must be passed in the same
order.
Return Values
The void keyword, used in the examples above, indicates that the
method should not return a value. If you want the method to return a
value, you can use a primitive data type (such as int, char, etc.)
instead of void, and use the return keyword inside the method:
int myMethod(int x)
float myMethod(float x)
double myMethod(double x, double y)
public class Main {
static int plusMethodInt(int x, int y) {
return x + y;
}
Access Modifiers
abstract Can only be used in an abstract class, and can only be used on
methods. The method does not have a body, for example abstract void
run();. The body is provided by the subclass (inherited from).