title: Class scope variable vs method scope variable
body: <p>I know that variable scope is enclosed by a start of block <code>{</code> and an end of block <code>}</code>. If the same variable is declared within the block, then the compile error <code>Variable already defined</code> occurs. But take a look at following example.</p>
  
  <pre><code>public class Test{
  int x=0;// Class scope variable
  
  public void m(){
    int  x=9;   //redeclaration of x is valid within the scope of same x. 
  
    if(true){
        int x=7; // but this redeclaration generates a compile time error.
    }
  
  }
  </code></pre>
  
  <p>Here, <code>x</code> can be redeclared in a method, although it's already declared in the class. But in the <code>if</code> block, <code>x</code> can't be redeclared.</p>
  
  <p>Why is it that redeclaration of a class scope variable doesn't generate an error, but a method scope variable redeclaration generates an error?</p>