Local variables

This is a tutorial about variable scope, a variable is a means to store data within the context of the program. For example, if you wish to store a numerical value then you would not store that number in a string, but within a integer or floating point number.

There are different types of variables, integer / string etc, but the scope of a variable is the area in which the variable is defined within block of code that it is situated.

This is some java code to demonstrate the difference between local variables and global.

class localvariable
       private static int value1 = 1;
       static public void globalVariable()
              System.out.println("Global : " + value1);
       static public void main(String args[])
              int value1 = 0;
              System.out.println("Local : " + value1);
       return 0;       

the output would be

Global : 1
Local : 0

Leave a Reply

Your email address will not be published. Required fields are marked *