Tutorial1 : Functions & Methods
Tutorial1 : Functions & Methods
The word public- means that the method itself can be called from
anywhere which includes other classes, even from different packages
(files) as long as you import the class
The second keyword, static -means that the method belongs to the
class and not any instance of the class ( object ).
However, if the keyword static was not there, then the method can be
invoked only through an object. int − return type
Void-return type.
The word void -means that the method doesn't return anything (it
does not return anything when you run the method).
1
Management Information Systems Dept.
Advanced Programming – MIS 301
a, b − formal parameters
Example
public static int minFunction(int n1, int n2) {
int min;
if (n1 > n2)
min = n2;
else
min = n1;
return min;
}
Method Calling
For using a method, it should be called. There are two ways in which a method
is called i.e., method returns a value or returning nothing (no return value).