Java final modifier: final modifier attribute, final modifier method and final modifier class
                                        
                    •
                    Java                                    
                1. Final modifies the attributes in the class
2. Methods in final modifier class
3. Final modifier class
Example 1
public class FinalTest {
    final int count = 1;
    public int updateCount() {
        count = 4;    // 修改final属性值,提示错误
        return count;
    }
    public final int sum() {
        int number = count+10;
        return number;
    }
}
public class FinalExtendTest extends FinalTest {
    public int sum(){};    // 重写父类 FinalTest 中的 sum()方法,出错
    int count = sum();    // 继承父类 FinalTest 中的 sum()方法
}
public static void main(String[] args) {
    FinalExtendTest fet = new FinalExtendtest();
    System.out.println(fet.count);
}
11
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        