Java: final Keyword


In Java, the final is keyword use with class, method, and variables. When it combined with one of these having below side effects on compile time:

  • A final class can not be instantiated.
  • A final method can not be overridden.
  • A final variable can not be re-assigned.

See Also: Difference between final, finally and finalize

final keyword Example

A final variable can not be re-assigned.

final variable example
Final Variable can be reassigned

A final class can not be subclassed.

Final Class Example
Final class can not be subclassed

A final method can not be overridden.

Final method Example
final method can not be overloaded

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s