Static Fields

Static or class fields belong to a class, not to an object

class Point {
    double x;
    double y;
    static double xorigin = 0.0;
    static double yorigin = 0.0;
  
}
System.out.println("The origin is at (" + Point.xorigin + ", " 
 + Point.yorigin + ")");

You access class variables with the name of the class rather than a reference variable.


Previous | Next | Top | Cafe au Lait

Copyright 1997-2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 2, 1997