final 关键字

在Java中,使用 final 关键字可以实现:
1. 定义不能被继承的类

2. 定义不能被覆写的方法,常量

 

全局常量(每个字母都大写): public static final 常量类型 常量名称 = 常量值;

public static final int ON = 1;
public static final int OFF = 0;
public class Demo{
    public static void main(String args[]){
        final String info = "mldn";
        String strA = "www.mldn.cn";
        String strB = "www." + info + ".cn";
        
        System.out.println(strA == strB);
    }
}
/*------------------------------------
E:\Javacode>java Demo
true

E:\Javacode>*/

 

posted @ 2019-02-19 17:34  眉毛病  阅读(107)  评论(0编辑  收藏  举报