首页 > 其他 > 详细

static final常量

时间:2015-08-15 00:05:45      阅读:264      评论:0      收藏:0      [点我收藏+]

package oo.day06;
//static final常量
public class StaticFinalDemo {
public static void main(String[] args) {
//Aoo.NUM = 250; //编译错误,常量不能修改
//System.out.println(Aoo.NUM);

//1.方法区中加载Boo.class
//2.将NUM1存储在方法区中
//3.去方法区中获取NUM1的值并输出
System.out.println(Boo.NUM1);

//编译器在编译时直接被替换为具体的值,效率高
//等价于System.out.println(6);
System.out.println(Boo.NUM2);
}
}
class Boo{
public static int NUM1 = 5; //静态变量
public static final int NUM2 = 6; //常量
}

 

 

 


class Aoo{
public static final int NUM = 5; //常量
//public static final double PI; //编译错误,必须声明同时初始化
}

 

static final常量

原文:http://www.cnblogs.com/xiaziteng/p/4731403.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!