java变量
1.局部变量
局部变量在方法以内,只有这个方法能用
2.实例变量
实例变量在所有方法外,作用域在整个类,但是使用的时候需要new这个对象才能用。
3.类变量
类变量在所有方法外,前面有static,作用域在整个类,使用的时候并不需要new这个对象才能用。
变量命名规范
- 所有变量、方法、类名见名知意
- 类成员变量:首字母小写和驼峰原则:monthSalary,除了第一个单词以外,其他单词首字母大写
- 局部变量:首字母小写和驼峰原则
- 常量:大写字母和下划线:MAX_VALUE
- 类名:首字母大写和驼峰原则:Man,GoodMan
- 方法名:首字母小写和驼峰原则:getClass();