Final, Finalize and Wrapper Classes
Final Keyword
Used to restrict the modification of classes, methods, and variables
- Final Variables: A
finalvariable’s value cannot be changed once it has been assigned. This makes it similar to a constant. - Final Methods: A
finalmethod cannot be overridden by subclasses. This prevents any further modification of the method’s behavior in derived classes. - Final Classes: A
finalclass cannot be subclassed. This means no other class can inherit from afinalclass.
Finalize
It is a protected and non-static method of Object class. It is invoked by JVM when an object is garbage collected.
With the release of JDK 9 finalize() has been deprecated.
Wrapper Classes
Class that wraps primitive data types.
Ex - Character, Byte, Integer, Boolean
Autoboxing - Conversion of primitive to object of their corresponding class. int to Integer.
int a = 5;
Integer b = a;