变量

变量

public class Demo{
    static int salary=3000; //类变量 多加了一个static关键词 遵守驼峰原则,第一个单词小写,后面都大写
    String str="hello world";//实例变量
    
    public static void main(String[] args) {
        System.out.println(salary);
    }
    public void method(){
        int i=0;//局部变量
    }
}

常量

public class Demo3 {
    static  final double PI=3.14;//使用final关键词定义常量
	//一般常量都大写
    public static void main(String[] args) {
        System.out.println(PI);
    }
}
posted @ 2023-06-04 21:43  晚枫zz  阅读(8)  评论(0)    收藏  举报