day08
## 变量


- 类变量:独立于方法之外的变量,用 static 修饰。
- 局部变量:类的方法中的变量。
- 实例变量(全局变量):独立于方法之外的变量,不过没有 static 修饰。
## 常量


public class Demo04 {
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 = "fangbiao";
char x = 'x';
double pi = 3.14;
}
}
public class Demo05 {
//类变量 static
static double salary = 3000;
//属性:变量
//实例变量:从属于对象;如果不自行初始化,这个类型的默认值 0 0.0
//布尔值:默认是false
//除了基本类型,其余的默认值都是null;
String name;
int age;
//main方法
public static void main(String[] args) {
//局部变量;必须声明和初始化值
int i = 10;
System.out.println(i);
//
Demo05 demo05 = new Demo05();
System.out.println(demo05.age);
System.out.println(demo05.name);
System.out.println(salary);
}
//其他方法
public void add(){
}
}
public class Demo06 {
//修饰符,不存在先后顺序
static final double PI = 3.14;
public static void main(String[] args) {
System.out.println(PI);
}
}

浙公网安备 33010602011771号