up previous next contents
Next: Fields Up: Classes and objects Previous: Objectives   Contents

A Simple Class

  • Each object is an instance of a class.
  • The basics of a class are it's fields and methods (or, attributes and behaviors).
        class Body {
           public long idNum;
           public String nameFor;
           public Body orbits;
           public static long nextID = 0;
        }
    
  • First declare the name of the class:
        Body mercury;
        Body earth;
    
  • mercury and earth are references to objects of type Body.
  • During it's existence, mercury may refer to any number of Body objects.
  • Note - this version of Body is poorly designed.


up previous next contents
Next: Fields Up: Classes and objects Previous: Objectives   Contents