- Java classes correspond to categories; Java class instances correspond
to individuals.
- Class definitions generally include instance variables, also known as
member variables, slots, or fields.
- If you want to define a class with public instance variables, then
instantiate the following pattern:
public class class name {
...
public instance-variable type instance-variable name;
...
}
- If you want to declare a variable such that the value of the variable
can be a class instance, then instantiate the following pattern:
class name variable name;
- If you want to create a new class instance, and you want to assign that new
class instance to a variable, then instantiate the following pattern:
variable name = new class name();
- If you want to declare a variable, initialized with a class instance, then
instantiate the following pattern:
class name variable name = new class name();
- If you wish to access an instance-variable value, then instantiate one
of the
following patterns:
... variable name.instance-variable name ...
variable name.instance-variable name = new-value expression;