The difference between the final and finally

final and finally Although it looks like, but the effect is different between them

A, final

Final: is a reserved word in java, can declare variables, methods, classes;
    Final modified variables: must be displayed by the user to specify the initial value, the initial value once there, can not be re-assignment; Further, for reference types variable, final reference type variable to ensure the address does not change, but the content can be changed.
    final modification of the method: the final modification of the method can not be rewritten, but the overload the
    final modification of the classes: a final class can not be inherited modified, e.g. String.

Two, finally

To ensure the physical resources try in such as database connections, network connections, etc. are recovered (must show recovery), java exception handling mechanisms finally, if an exception occurs whether the try, which case is executed, even or case executed in the try return statement, Code of the Federation finally be executed

Published an original article · won praise 0 · Views 15

Guess you like

Origin blog.csdn.net/yunwuguiqi/article/details/104313553