关于initializer的问题,详情请进

Patrick_DK Patrick_DK 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
英文不是很好,谁能帮忙解释一下下面这段话,并对应3个情况写3个例子看看?谢谢
Initializers are used in initialization of objects and classes and to define constants in interfaces. These initializers are :
1. Static and Instance variable initializer expressions.
Literals and method calls to initialize variables. Static variables can be initialized
only by static method calls.
Cannot pass on the checked exceptions. Must catch and handle them.
2. Static initializer blocks.
Used to initialize static variables and load native libraries.
Cannot pass on the checked exceptions. Must catch and handle them.
3. Instance initializer blocks.
Used to factor out code that is common to all the constructors.
Also useful with anonymous classes since they cannot have constructors.
All constructors must declare the uncaught checked exceptions, if any.
Instance Initializers in anonymous classes can throw any exception.(?)
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
Patrick_DK
Java SE 62,621 成员 307,251 内容