关于initializer的问题,详情请进

Patrick_DK 2002-01-05 03:23:40
英文不是很好,谁能帮忙解释一下下面这段话,并对应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.(?)
...全文
81 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Patrick_DK 2002-01-05
  • 打赏
  • 举报
回复
这三种情况的例子能写出来看看吗?
1。静态实例的Initilizer表达式
2。静态Initalizer包
3。实例Initalizer包

我有点糊涂
1.static int i=3;
2.static {....}
3.{....}

是不是这样啊?
oceayan 2002-01-05
  • 打赏
  • 举报
回复
回头个你续上
oceayan 2002-01-05
  • 打赏
  • 举报
回复
Initializer 常用于初始化类和对象,也可用于接口中的常量定义。
这些Initializer主要分以下几种:
1。静态实例的Initilizer表达式
2。静态Initalizer包
3。实例Initalizer包

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧