The original
Link: www.nowcoder.com/questionTer… Source: Niuke.com
1. Final is a keyword. Final can modify classes, methods, and properties. If a class is final, so this class is the final class, cannot derive new subclasses, and not as the parent class be inherited, all methods in the class can’t be rewritten, but in the final class member variables can be changed, to the final class member variables you can’t change, must add final modification to the member variable. Therefore, a class cannot be modified by both final and abstract; the two keywords contradict each other. If final modifies a method, the method is final and no subclasses are allowed to override it, but subclasses can still use the method. Note that final is used to indicate that the parameter cannot be modified inside the function. Final modifies properties. Variables modified by final are immutable. Immutable here has two meanings: reference immutable and object immutable. Final means that a reference is immutable, that is, it can only point to the object to which it was initialized, regardless of how the content of the reference changes. Therefore, a variable modified with final must be initialized, which is essentially a constant.
2. As part of exception handling, finally is used only in try/catch statements. Statements in the finally block must be executed and are often used to release resources, such as IO streams and database resources.
3. Finalize is a method of Object, which is declared in Object: Protected void Finalize () throws Throwable {} When the garbage collector executes, the Finalize () method of the collected object is called, which can be overridden to recycle its resources. Note: Once the garbage collector is ready to release the space occupied by an object, the Object’s Finalize () method will be called first, and the memory occupied by the object will be reclaimed only when the next garbage collection action occurs.