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
About

manveen

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today