The road less taken

« This leap year: hop... | Main | Java Serialization »
Tuesday Mar 04, 2008

Final keyword in Java

The Final keyword is used in Java on an entity that cannot be changed.

Here are a few different contexts in which final can be used:

Final class:

Meaning: A final class cannot be subclassed. Advantage: Security or efficiency. Example: java.util.System

Final method:

Meaning: The method cannot be overridden in a subclass. Advantage: Preventing unexpected behavior crucial to the functionality of the class.

Final variable:

Meaning: The variable is immutable, meaning once assigned, it cannot be reassigned. This is different from constant keyword since constant should be known at compile time and final need not be. Advantage: Optimization.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed