Java: Static Methods
/**
* A example of a Static Greatest Common Factor class.
*
* @author (Mister V)
* @version (April 2013)
*/
public class GCF
{
/** instance variables declared here
* but instance variable can not be used in a static method.
*/
/** static variables can be defined here and used in static methods
* often only used for constant values with in the class.
*/
/**
* Constructor for objects of class GCF
* If the class is never needed as an object, the constructor is not needed.
*/
// public GCF()
// {
// }
/**
* Static Methods
* do not use instance variables of the class that the method is defined.
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public static int gcf(int n, int d)
{
int gfc =1;
// put your code for the euclidean algorithm here
return gfc;
}
}
To call a static method from a different class:
int gcf = GCF.gcf(n,d);