Attribute Variables (variables declared outside of a method and without the keyword static) are called Member or Instance Variables. Instance Variables contain data specific to a particular object instance which is instantiated from a class.
Local Variables are variables defined within methods. They are only used within the method in which they are declared.
Uses for Variables:
- Store unique attribute data for an Object Instance
- Assign the value of one variable to another variable
- Represent values within a mathematical expression
- Print values to screen
- Hold references to other objects
Variable Declaration and Initialization:
Instance Variable Syntax:
[modifiers] type identifier [=value];
Local Variable Syntax:
type identifier;
identifier = value;
or
type identifier = [value];
Do not use [modifiers] in Local Variables declaration.
0 comments:
Post a Comment