变量,局部变量,实例变量,类变量, 常量


变量,局部变量,实例变量,类变量, 常量

public class Demo07 {
    public static void main(String[] args) {
        //int a,b,c;
        //int a = 1, b = 2, c = 3;//不要这样写,影响程序的可读性
        String name = "zuifengdeyang";
        char x = 'c';
        double pi = 3.14;
        System.out.println(x);
        System.out.println(pi);
        System.out.println(name);
        }
}

public class Demo08 {
    //类变量  static
    static  double salary = 2500;

    //属性:变量


    //实例变量:从属于对象;如果不自行初始化,这个类型的默认值 00.0
    //布尔值:默认是false
    //除了基本类型,其余的默认值都是null;
    String name;
    int  age;



    //main方法
    public static void main(String[] args) {
        //局部变量;
        int i = 10;
        System.out.println(i);

        //变量类型    变量名字 = new Demo08();
        Demo08 demo08 = new Demo08();
        System.out.println(demo08.age);
        System.out.println(demo08.name);

        //类变量  static
        System.out.println(salary);
    }

    //其他方法

    public void add(){
    }
}

public class Demo09 {

    //修饰符,不存在先后顺序
    static final double PI =3.14;

    public static void main(String[] args){
        System.out.println(PI);
    }
}

相关