Index

Overview


Okay we've learned that it's cool to send messages.

But how do objects handle messages? What is that "object access point"?

Introducing "methods". A method is the code that will receive a message.

When a method is defined (coded) then we can send messages using that method name to object instances the given type.

A class will generally have many methods.

Before starting, we want to understand the big three.

  • Object "A" sends a message to Object "B"
  • Object "B" defines a "method" to handle the given message.

Note that the (sent) message name must match the (receiving) method name (in this example "hello")
  • Object "A" sends a message to Object "B"
  • Similar to the previous example except in this case Object "B" has a method named "whatIsYourName". This method also returns a value to the message sender.

In this example the method returns a "String" object. However, different methods will return a variety of different object types
  • The teacher object sends a message "hereIsYourScore" but also includes the object '100' along with the message
  • The student object provides a method "hereIsYourScore" that accepts the value along with the message. We call the value a method parameter.

  • The number of method parameters can be zero to many
  • The object types of the parameters may be int, String, etc.
  • We use the words method parameters and method arguments interchangeably