Glossary
Immutable
Describes a class or object whose state cannot be changed after it has been created. Such classes have no mutator methods.
Example:
A String
object in Java is immutable; once you create it, you cannot change its characters, only create a new String
.
Mutator methods (setter methods)
Methods that change the values of an object's instance variables, often by taking a new value as a parameter. They are also known as setter methods.
Example:
To update a player's score, you might call player.setScore(100);
, which is a mutator method that modifies the score
instance variable.
Parameter
A variable defined in the header of a method that receives a value when the method is called, allowing data to be passed into the method.
Example:
In public void setVolume(int level)
, level
is a parameter that specifies the new volume setting.
Return type
The data type of the value that a method sends back to the caller after its execution. If a method does not return a value, its return type is `void`.
Example:
In public int getAge()
, int
is the return type, indicating the method will provide an integer value.
Void methods
Methods that do not return any value after their execution. They are typically used to perform an action or modify an object's state.
Example:
A printReport()
method that displays information to the console but doesn't return data is a void method.