Home > Java > Javagetting Started > body text

The difference between final, finally and finalize in java

王林
Release: 2019-11-29 14:04:46
forward
2207 people have browsed it

The difference between final, finally and finalize in java

The difference is as follows:

final: Modifier (keyword), used to declare attributes, methods and classes, respectively indicating that attributes are immutable, methods cannot be overridden, and classes Not inheritable.

Therefore a class cannot be declared both abstract and final. Declare variables or methods as final to ensure that they will not be changed during use. Variables declared as final must be given an initial value when declared (lazy initialization can also be used), and can only be read in subsequent references and cannot be modified. Methods declared as final can also only be used and cannot be overloaded.

Java introductory teaching video recommendation: java learning video

finally: It is part of the exception handling statement structure, indicating that it is always executed.

finalize: It is a method of the Object class. Java technology allows the use of the finalize() method to do necessary cleanup work before the garbage collector clears the object from the memory. This method can be overridden to provide garbage collection. For other resource recycling, such as closing files, etc., the JVM does not guarantee that this method will always be called.

Recommended related articles and tutorials: Introduction to java language

The above is the detailed content of The difference between final, finally and finalize in java. For more information, please follow other related articles on the PHP Chinese website!

source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template