Variable Declarations in Java Programming

Variable Declarations in Java Programming

Previous Home Next

 

When a variable declaration is executed, memory is allocated for the variable. 
This memory must be initialized to contain some definite value before the variable can be used in an expression

When a variable declaration is executed, memory is allocated for the variable. 
This memory must be initialized to contain some definite value before the variable can be used in an expression.
 In the case of a local variable, the declaration is often followed closely by an assignment statement
that does the initialization.

Declaration of variable

int count; // variable is declared with the name count
count = 0; // variable count is initialized with 0

OR Variable can also be declared as
int count = 0; // declaration and initialization at same time
 


 
class Test 
{
public static void main(String[] args)
{
int i;
class Local

{
for (int i = 0; i < 10; i++)
{
System.out.println(i);
}

Previous Home Next