1-4 Java se- constant & variable - Scope

Scope: Starting line defined variables, until the end of the braces so far belongs

If the variable is defined in brackets, outside the parentheses is less than the acquisition value, because each parenthesis is a scope, outside of the scope of things can not be called something inside

1     public static void main(String[] args) {
2         {
3             int num = 60;
4             System.out.println(num);
5         }
6         System.out.println(num);
7     }

If you want to get outside the parentheses can be a variable, it can define a variable outside the parentheses to obtain its value, key variables can be defined in different scopes same

 

    public static void main(String[] args) {
        {
            int num=8;
            System.out.println(num);
        }
        int num=10;
        System.out.println(num);
    }

 

 

 

Guess you like

Origin www.cnblogs.com/KeepCalmAndNeverSayNever/p/11825463.html