<<< Implementation and Interface Considerations     Index     Database Reader class example >>>

6. Controlling Object Creation


  • 
    public class Planet
    {
        int distance;   // distance from star
        int satellites; // # of satellites
        double mass;    // the mass
    
        public Planet() // default constructor
        {
            this.distance = 0;
            this.satellites = 0;
            this.mass = 0;
        }
    
    
  • 
    public class GasGiant extends Planet
    {
        public GasGiant()
        {
            // Explicit call to
            // base constructor:
            super();
        }
    }
    
    
  • 
        public Planet(int distance, int satellites, double mass)
        {
            this.distance = distance;
            this.satellites = satellites;
            this.mass = mass;
        }
    }
    
    
<<< Implementation and Interface Considerations     Index     Database Reader class example >>>