变量
大概简介
![](C:\Users\ZC905\Pictures\Screenshots\屏幕截图 2023-09-18 175232.png)
实例操作
public class Demo06 {
public static void main(String[] args) {
//int a,b,c;
//int a=1,b=2,c=3; //程序可读性
int a = 1;int b = 2;int c = 3;
String name = "qinjiang";
char x = 'x';
double pi = 3.14;
}
}
变量作用域
![](C:\Users\ZC905\Pictures\Screenshots\屏幕截图 2023-09-18 232044.png)
实践操作
public class Demo07 {
//类变量 staatic
static double salary = 2500;
//属性:变量
//实例变量:从属于对象:如果不自行初始化,这个类型的默认值 0 0.0 u0000
//布尔值:默认是false
//除了基本类型,其余都是null;
String name;
int age;
//static{}
//main方法
public static void main(String[] args) {
//局部变量:必须声明和初始化值
int i = 10;
System.out.println(i);
//变量类型 变量名字 =new Demo07();
Demo07 demo07 = new Demo07();
System.out.println(demo07.age);
System.out.println(demo07.name);
//类变量 staatic
System.out.println(salary);
}
}
实验结果
10
0
null
2500.0
Process finished with exit code 0
常量
![](C:\Users\ZC905\Pictures\Screenshots\屏幕截图 2023-09-18 233822.png)
实践操作
public class Demo08 {
//修饰符,不存在先后顺序
static final double PI= 3.14;
public static void main(String[] args) {
System.out.println(PI);
}
}
实验结果
3.14
Process finished with exit code 0
变量的命名规范
驼峰方法
![](C:\Users\ZC905\Pictures\Screenshots\屏幕截图 2023-09-18 234726.png)