5-1 final

package fivetwo;
public class Employee{
    private String str;
    private int x;
    
    private final int y;
    private final String str2;
    
    public Employee(){
        this.y = 3;
        this.str2 = "ss";
    }
    
    /*
     * final修饰的类或方法不允许扩展
     * final修饰的域必须赋初值,初始化的两种时机:(只能赋值一次)
     *1)域声明时
     *2)构造方法中赋值
     */
    
    public static void main(String[] args) {
        Employee e =  new Employee();
        System.out.println(e.y);
        System.out.println(e.str2);
    }
    
}

 

posted @ 2018-01-02 11:18  aLa神灯  阅读(105)  评论(0编辑  收藏  举报