In Java, what does the ‘final’ modifier mean when applied to a method, class, and an instance variable?
When applied to a method definition the final modifier indicates that the method may not be overridden in a derived class.
当定义一个方法的时候用到了final这个修饰符号,说明这个方法是不能再子类中覆写的
When applied to a class, the final modifier indicates that the class can not be used as a base class to derive any class from it. It’s also good to point out in an interview that the final modifier, when applied to either a class or a method, turns off late binding, and thus prevents polymorphism.
当定义一个类的时候用到了final这个修饰符号,表明这个类不能用作基类去派生子类,无论是用作方法还是类上面,不能再向后衍生了,从而阻止了多态的效果
And, when applied to an instance variable, the final modifier simply means that the instance variable can’t be changed.
而,当它修饰一个实例变量的时候,final修饰符仅仅意味着被修饰的变量是不能被改变的