How to declare a local variable in Java?


Local variables are declared in methods, constructors, or blocks. Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block.

A local variable is the one which is declared within a method. The scope of this variable is within the method.

Example

public abstract class Sample {
   public static void main(String args[]){
      int data = 4044;
      System.out.println(data);
   }
}

Output

4044

Updated on: 30-Jul-2019

595 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements