Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

final method in java [closed]

Tags:

java

I got the question in an interview, can final method override....?

I said YES. Interviewer has got strange gesture. What is wrong with it? Grammatically it is correct answer, I guess. final methods can override, but final method cannot be overridden.
Was my answer correct?

I found some people are interested to reopen this question.

like image 857
AmitG Avatar asked Aug 01 '26 08:08

AmitG


2 Answers

If his English was bad, then you should've tried to clarify what he means. Communication is a very important aspect of building software.

Apart from that:

  • final methods can override other methods
  • final methods cannot be overridden.
like image 143
Bozho Avatar answered Aug 03 '26 22:08

Bozho


final (Java)

In the Java programming language, the final keyword is used in several different contexts to define an entity which cannot later be changed.

A final method cannot be overridden by subclasses. This is used to prevent unexpected behavior from a subclass altering a method that may be crucial to the function or consistency of the class.

like image 29
CloudyMarble Avatar answered Aug 03 '26 22:08

CloudyMarble



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!