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