Alternate ways to access static members:

  1. Recall that: a public static method is invoked using:

    
          className.staticMethod(parameters)   
    
    

  2. A public static variable (like static methods) can be accessed using:

    
          className.staticVariableName    
    
    

    Example:
          public class Numeric
          {
    	 public static int X;
    
             public static boolean approxEqual(double x, double y)
             {
                final double EPSILON = 1E-10;  // 10^(-10)
                double xyMax;
    
                xyMax = Math.max( Math.abs(x), Math.abs(y) );
                return( Math.abs(x - y) < xyMax*EPSILON );
             }
          }
    
          public class myProgram
          {
             public static void main(String args[])
    	 {
    	    ...
    	    Numeric.X = 0;
    	 }
          }
    

  3. static members (methods & variables) can also be accessed using a instance variable of that class:

    Example:
          public class Numeric
          {
    	 public static int X;
    
             public static boolean approxEqual(double x, double y)   
             {
                final double EPSILON = 1E-10;  // 10^(-10)
                double xyMax;
    
                xyMax = Math.max( Math.abs(x), Math.abs(y) );
                return( Math.abs(x - y) < xyMax*EPSILON );
             }
          }
    
          public class myProgram
          {
             public static void main(String args[])
    	 {
    	    Numeric y = new Numeric();
    	    ...
    	    if ( y.approxEqual(0.1, 0.12) )
    	       ...  instead of Numeric.approxEqual(0.1, 0.12)
    
    	    y.X = 0;  
    		    instead of Numeric.X = 0;
    	 }
          }
    
    

    • NOTE: the compiler will NOT pass y as an implicit parameter to approxEqual because approxEqual is defined as static