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.

กก

List Previous | Next