Home Segments Top Top Previous Next

156: Mainline

In general, a declaration is a program element that provides a compiler with essential information or useful advice. For example, when you introduce a local variable or parameter, you are said to declare it, because you tell the compiler its type. On the other hand, no memory is set aside for local variables or parameters at compile time, because neither local variable memory nor parameter memory exists until the method is called.

In contrast, a definition causes a compiler to set aside memory at compile time. For example, when you introduce a class variable, you both declare and define the variable, because you inform the compiler about the variable's type and you cause the compiler to set aside memory for the variable at compile time.

Generally, when a variable is both declared and defined, you say, as a shorthand phrase, that it is defined; otherwise, it is declared.