What is final keyword in Java?

DWQA QuestionsCategory: JavaWhat is final keyword in Java?
Editor Staff asked 1 month ago

What is final keyword in Java?

1 Answers
Editor Staff answered 1 month ago

final is a special keyword in Java that is used as a non-access modifier. A final variable can be used in different contexts such as:
final variable
When the final keyword is used with a variable then its value can’t be changed once assigned. In case the no value has been assigned to the final variable then using only the class constructor a value can be assigned to it.
final class
When a class is declared as final in Java, it can’t be extended by any subclass class but it can extend other class.
 
final method
When a method is declared final then it can’t be overridden by the inheriting class.