Google+

182. Local Variables and Instance Variables







Variable is a name of the memory location.

Example -

int var = 5;

Here var is the variable. It stores the assigned value 5 in its memory location.

What are Local Variables ?

A variable that is declared inside the method is called as Local Variable.

What are Instance Variables ?

A variable that is declared inside the Class but outside the methods is called as Instance Variable.

Example of Local Variable and Instance Variable 

Class One
{
         int var1 = 5;   // Instance variable (Declared inside the Class One but is not inside any method)

        two( )
        {
               int var2 = 8;   //Local variable (Declared inside the method)
         }
 
}

So, variables declared inside the methods of Class are Local Variables and inside the Class but outside the methods are Instance Variables.





Please comment below to feedback or ask questions.

Java and the Windows Command Prompt will be explained in the next post.





No comments:

Blog Index