Generally, a declaration of a variable consists of a type and an identifier. The simplest form is,
type identifier;
type: type of the thing we want to store, usually the type is a class name
identifier: name that programmer choose to give to the variable. Though there is no rules for what kind of name we should give to the variable, we usually choose a name that describe the function of the variable so that it could be easy to understand and make changes afterwards for us.
When we declared a variable, the computer allocate a part of the memory to install the variable. |
Declaring local variable
Example:
Elephant elephant;
type: Elephant
Notice: In the program given at home page, we imported the class so that we don't need to mention it in declaring. But the standard way to write the type is lab4lib.Elephant."lab4lib" is the class of "Elephant." It is the same when declaring other kind of variables.
identifier: elephant
Naming Covention: Begin with a lower case letter, and the first letter of each subsequent word in method name is capitalized. |