Definition of variables and variables defined in the preceding

 
 
public  class Error {

    
    {
        i=5;
    }
    int i = 1; // set to a member variable i
     // the Java to detect a variable i, from top to bottom and asked to find definitions or declarations i, have not found it could not determine the member variables or local variables
     // will the default declare int i = 1 this variable is marked as a member variable, so that you can find in a global variable mode; and because it is marked as
     // a member variable, so it can only be assigned can not do anything else until found hereinafter defined variable with the same name, this time to put the tag removed,
     // assign a value to a variable of the same name, i.e. codes appeal to define a variable i = 5; marked as the member variables i, go down, i found the definition of the same name
     // int i this time will be 5 assigned to i, and because int i = 1; 1 and 5 overwritten, so the final value is 1
    
    /*{
        b + = 5; // can not do operations other than assignment
    }
    int b=1;*/
    public static void main(String[] args) {
      

    }

}
 
 

 

 

 

Guess you like

Origin www.cnblogs.com/xuwangqi/p/11097729.html