How to declare a local variable in Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 10-Jan-2018 06:21:07
Advertisements