Home Segments Top Top Previous Next

250: Mainline

Once you have decided in which classes instance variables and instance methods should be declared and defined, you can proceed to define the classes, and to link them up in a class hierarchy.

The following definition of the Attraction class contains the minutes instance variable and a zero-parameter constructor with a statement that announces its use:

public class Attraction { 
 // Define instance variable: 
 public int minutes; 
 // Define zero-parameter constructor: 
 public Attraction () { 
  System.out.println("Calling zero-parameter Attraction constructor"); 
  minutes = 75; 
 } 
 public Attraction (int m) {minutes = m;} 
}