how final modifier works in java
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.
- 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.
- And, when applied to an instance variable, the final modifier simply means that the instance variable can’t be changed.
|
About Blog No Baap -
Since 2016 BlogNoBaap has been bringing you the very best in all types of web resources. Posted daily, and delivered straight to your inbox each morning.