Glossary
Accessor methods
Methods that allow other objects, classes, or users (clients) to access the data of an object. They are typically declared as public.
Example:
A BankAccount object might have an accessor method getBalance() to retrieve the current account balance.
Clients
Other objects, classes, or users that interact with and access the data or functionality provided by a given object.
Example:
In a game, the GameController class acts as a client to the Player object, calling its methods to move the player or check their score.
Getter methods
A specific type of accessor method used to retrieve the value of a particular instance variable. Their return type matches the type of the variable being returned.
Example:
To get the name of a Dog object, you would call its getter method, getName(), which returns a String.
Non-void
Refers to methods that declare a specific data type (like `int`, `String`, or an object type) in their signature, indicating they will return a value of that type.
Example:
A method public boolean isValid() is non-void because it's designed to return a boolean value indicating validity.
Return a copy of that reference
When an object is returned from a method, a copy of its memory address (reference) is returned, not a new copy of the entire object. Both the original and returned references point to the same object in memory.
Example:
If a method returns a Car object, it's actually returning a copy of that reference to the Car object, so any modifications made via the returned reference will affect the original Car object.
Return by value
When a primitive data type is returned from a method, a copy of its value is returned. The original variable remains unchanged.
Example:
If a method returns an int like return 10;, the calling code receives a copy of the value 10; the original variable that held 10 is unaffected, demonstrating return by value.
Return keyword
A keyword used in methods to send a value back to the caller and immediately terminate the method's execution, returning control to the point where the method was called.
Example:
In a calculateArea method, once return area; is executed, the method stops, and the area value is sent back to the line of code that called calculateArea, illustrating the return keyword's control flow.
toString()
A special accessor method that returns a string representation of an object's information. It is automatically invoked when an object is printed.
Example:
When you System.out.println(myBook);, the myBook object's toString() method is called to display details like 'Title: The Great Novel, Author: A. Writer'.