Final Keyword Interview Questions

By using final keyword we can make
  • Final class
  • Final method
  • Final variables
  • If we declare any class as final we can not extend that class
  • If we declare any method as final it can not be overridden in sub class
  • If we declare any variable as final its value unchangeable once assigned
Abstract methods must be overridden in sub class where as final methods can not be overridden in sub class
  • If a class needs some security and it should not participate in inheritance in this scenario we need to use final class.
  • We can not extend final class.
No We can not declare interface as final because interface should be implemented by some class so its not possible to declare interface as final.
  • No. Its not possible to declare a final variable without initial value assigned.
  • While declaring itself we need to initialize some value and that value can not be change at any time.

No.Constructors can not be final.
Compile time error will come :Cannot override the final method from Super class
Yes we can create object for final class.
final keyword in java is used to make any class or a method or a field as unchangeable. You can’t extend a final class, you can’t override a final method and you can’t change the value of a final field. final keyword is used to achieve high level of security while coding.
Uninitialized final field is called blank final field.
Whenever necessary especially if you want to do equality check or want to use your object as key in HashMap.
Yes, we can change the state of an object to which a final reference variable is pointing, but we can’t re-assign a new object to this final reference variable.
Abstract methods must be overridden in the sub classes and final methods are not at all eligible for overriding.
A final class is very useful when you want a high level of security in your application. If you don’t want inheritance of a particular class, due to security reasons, then you can declare that class as a final..
No, we can’t change the value of an interface field. Because interface fields, by default, are final and static. They remain constant for whole execution of a program..
final class —> can not be extended.
final method —> can not be overridden in the sub class.
final variable —> can not change it’s value once it is initialized.
No. Only final local variables can be used inside a local inner class.
No, constructors can not be final.