Java Final, Finally, Finalize

本文详细解释了Java中final关键字的三种使用方式:定义常量变量、不可覆盖的方法及不可继承的类。此外还介绍了finally块的执行条件及其不被执行的情况,并简述了finalize方法的作用。

Final is a Keyword, final can be used in three different ways:

  1. final variable
  2. final method
  3. final class


  1. final variable 基本上就是 constant,一旦被赋值,就不能被变更;如果在class里declare a final variable, 那么在此class生成出的object就必须对这个 final variable赋值。
  2. final method 是method can't be over overridden.
  3. final class is a class can't be inherited.

Finally is used in try/catch block, it is guaranteed to be executed no matter exception is thrown or not. 

Circumstances that finally block are NOT executed: 

  1. System.exit() is called in try block
  2. Another thread interrupts current one
  3. JVM crashes first

 

Fianllize is a method. finalize() is called by Garbage collection thread just before collecting eligible objects.

转载于:https://www.cnblogs.com/Dylan-Java-NYC/p/4825063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值