Subsections
- All parameter methods are "pass by value".
- Values of a parameter are copies of the values in the invoking method.
- When the parameter is an object, the object reference is passed by value.
- End result: primitives cannot be modified in methods, objects can.
- If data fields (attributes) are public, programmers can change them.
- Generally want to hide the data from programmers that will use the class.
- If programmers can access a class's fields directly, you have no control over what values they can assign.
- In the Body example, nextIDshould be private.
- If necessary, you should provide get methods that allow programmers to determine the current field value, and set methods to modify the value. These are called accessors (get) and mutators (set).
Next: this
Up: Classes and objects
Previous: Constructors
  Contents
|
|