JAVA variables, constants, scope

Variables, constants, scope

variable:

A variable is the amount of change.

JAVA is a strongly typed language, and each variable must declare its type.

JAVA variable is the most basic storage unit in the program, and its elements include variable name, variable type and scope.

// 变量类型 变量名 = 值;
	int    number = 10;

Every variable has a type, which can be a basic type or a reference type


Variable scope:

  • Class variable

  • Instance variable

  • Local variable

    public class Hello{
          
          
        static int a = 0;//类变量 从属于类
        String str = "hello";//实例变量  在此类中可以使用 从属于此对象 
        //实例变量如果不初始化择变为默认值0/null
        public void method(){
          
          
            int i =0;//局部变量  只能在此方法引用
        }
    }
    

constant:

A value that cannot be changed after initialization.

//final 常量名= 值;
final double PI = 3.14

Constant names are generally capitalized.

Guess you like

Origin blog.csdn.net/qq_33956536/article/details/106463553