In Java, what purpose do the keywords final, finally and finalize fulfil?
In Java, what purpose do the keywords final , finally and finalize fulfil?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
final
finalcan be used to mark a variable “unchangeable”finalcan also make a method not “overrideable”finalcan also make a class not “inheritable”. i.e. the class can not be subclassed.finally
finallyis used in a try/catch statement to execute code “always”Java 7 has a new try with resources statement that you can use to automatically close resources that explicitly or implicitly implement java.io.Closeable or java.lang.AutoCloseable
finalize
finalizeis called when an object is garbage collected. You rarely need to override it. An example: