Local Variable Declarations in Java Programming
Previous | Home | Next |
Local Variables Similar to how an object stores its state in fields, a method will often store its temporary state in local variable
The syntax for declaring a local variable is similar to declaring a field (for example, int Number = 0;).
There is no special keyword designating a variable as local;
Local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.
They are called local because they can only be referenced and used locally in the method in which they are declared. l
The variable meters is declared locally inside the method convertKmToM.it has scope only inside the method.
private static double convertKmToM(double kilometers)
{
double meters = kilometers * 1000;
return meters;
}
Previous | Home | Next |