title: Local Variable Initialization Java
body: <pre><code>public class LocalVariables {
  
      static public void main(String args[]){
  
          int var;
  
          if(args.length &gt; 0){
              var = 10;
  
          }
  
          else{
              var = 20;
          }
          System.out.println(var);
      }
  
  }
  </code></pre>
  
  <p>Here if I remove <code>else</code> part it's showing compilation error as:</p>
  
  <pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
  The local variable var may not have been initialized
  </code></pre>
  
  <p>Explain how the local variable value is initialized if I use <code>else</code> part.</p>