Local Variable

 

//Local Variable:-

  • //The Variable which is Declared inside the method/block/constructor is called Local variable
  • //The scope of Local Variable Remains Only within the method/block/constructor.
  • //It is also called Temporary variable.
  • //Local Variable cannot defined with Static Keyword.
  • //We can not declare more than one local variable of same Name within the Method.
  • //Local variable does not have default value in java. we need to provide the value otherwise it shows error.

====================================================================

//Program I:-

package variableStudy;

public class LocalVariable

{

       //i.Local Variable is Declared inside the method/block/constructor. 

       //Example of Local Variable

       public static void main(String[] args)

           {           

              String name="Rupali"; // inside the Method. 

           }

               {

              int age=20;   //inside the block.      

               }      

       public LocalVariable()

           {

              float weight=38.22f; //inside the constructor.

           }       

 }

====================================================================

Post a Comment

0 Comments