Document

变量与常量

变量

 

 

 

import java.sql.SQLOutput;
​
public class Demo04 {
​
   //属性:变量
​
   //static 类变量
   static double adad = 121234;
​
   //实例变量:属于对象
   int age;
   String name;
​
​
   //main 方法
   public static void main(String[] args) {
       //局部变量
​
​
       //布尔值默认值:false
       //除了基本类型其余的都是null
       Demo04 demo04 = new Demo04();
       System.out.println(demo04.age);//0
       System.out.println(demo04.name);//null
​
​
       //调用add()方法
       add();
  }
​
   //其他方法
   public static void add() {
       //static 类变量
       System.out.println(adad);//121234.0
  }
​
​
​
}
​

常量

public class Demo05 {
   //修饰符不区分前后
   //final 修饰的变量名用大写,因为它不需要改变
   final static  double FI = 3.14;
   public static void main(String[] args) {
       System.out.println(FI);
  }
}


posted @ 2022-07-25 15:24  一蓑烟雨任平生。。  阅读(28)  评论(0)    收藏  举报
Document