The Java Program: BodyMain1.java

  1 // BodyMain1.java:  recursive class with classwide (static) variable
  2 
  3 class Body {
  4    long idNum;
  5    String nameFor;
  6    Body orbits;
  7 
  8    static long nextID = 0;
  9 }
 10 
 11 class BodyMain1  {
 12 
 13    public static void main (String args[])  {
 14 
 15       Body sun   = new Body();
 16       sun.idNum  = Body.nextID++;
 17       sun.nameFor= "Sol";
 18       sun.orbits = null;        // Sol orbits no body
 19 
 20       Body earth   = new Body();
 21       earth.idNum  = Body.nextID++;
 22       earth.nameFor= "Earth";
 23       earth.orbits = sun;
 24 
 25    }
 26 
 27 }