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
Last Modified September 2, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu