Object: Using Objects

Using Objects

Once you've created an object, you probably want to use it for something. You may need to use the value of one of its fields, change one of its fields, or call one of its methods to perform an action.

Referencing an Object's Fields

  • Object fields are accessed by their name.
  • You may use a simple name for a field within its own class.
  • Code that is outside the object's class must use an object reference or expression, followed by the dot (.) operator, followed by a simple field name.

Calling an Object's Methods

ObjectReference.methodName(argumentList);
ObjectReference.methodName();
  • You use an object reference to invoke an object's method.
  • You append the method's simple name to the object reference, with an intervening dot operator (.).
  • Provide, within enclosing parentheses, any arguments to the method. If the method does not require any arguments, use empty parentheses.

Object: Using Objects — Structure map

Clickable & Draggable!

Object: Using Objects — Related pages: