Why to use final method in java programs? – Is it inherited?

Answer: final method in java programs is used to stop being overridden in derived class. However, java final method can be inherited in derived class.

Note that final method can be used in any normal class and not only to final class in java programs.

In below java code example, Insurance class is the base class that is having final method “public final void InsuranceQuote() “ and normal method “public void process()” . The derived class InsuranceAgent cannot override final method InsuranceQuote() for its own implementation and have to use base class InsuranceQuote() method, but can override process() method.

 

 

NOTES:

Final method can be overloaded in java programs, In below example, we have overload two final methods given below.
public final void InsuranceQuote()
public final void InsuranceQuote(String premium)

Example:

 

 

CONCLUSION:

  • final method cannot be overridden in java
  • final method can be overloaded in java.
  • final method can be inherited in java
  • final method cannot be abstract in java

Recommended to read the interview question i.e. Can a method be final and abstract both in java?

Read More