next up previous
Next: Scope of local variables Up: Unit 03 Previous: Example: modification of an

Local variables

The body of a method can contain variable declarations. Such variables are called local variables. In fact, all variables that we have used till now were local variables, since they were declared in the body of a method, namely the main() method. Hence, they are used as we have seen in Unit 2.

Here, we concentrate on two fundamental aspects related to variables:

Note: In Java, it is also possible to define global variables for a class. A global variable is defined inside the class, but outside any method, and is qualified as static. In this course we will not make use of global variables.


next up previous
Next: Scope of local variables Up: Unit 03 Previous: Example: modification of an