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

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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