当final修饰的是基本数据类型时和String,如果在编译期间就知道它的值。则编译器会把它看作编译器常量,所以相当于直接访问常量,只有此种情况才可以这样处理。
final String s="hello"; String a="hello2"; String b="hello"; String c="2"; String d=b+2; String e=s+2; System.out.println(a==d);//false System.out.println(a==e);//true
//因为不是基本类型,不相当于直接更改吧(我也不是很明白) final String s="hello"; String a="hello2"; String b="hello"; String c="2"; String d=b+c; String e=s+c; System.out.println(a==d);//false System.out.println(a==e);//false
final 修饰的变量必须要赋值才可以使用(最终类)
static 修饰的变量转为赋初值,在能在类主体中定义(修饰全局变量),不能在方法中定义(修饰局部变量),且在不同的实例中地址一样,存储在全局区.
局部变量:Java方法中的“形参”是局部变量
方法内的变量是“实参”
static不允许修饰外部类,因为这样在类加载的时候就会全部加载, 正常应该在使用时才允许调用
A static method can access only sttic data,It can not access non=static data(instance variables)
实例方法---构造方法, 类方法---静态方法