解释一下输出结果是怎么产生的?

Mritlee 2020-07-30 10:42:40
public class Text {
public static int k = 0;
public static Text t1 = new Text("t1");
public static Text t2 = new Text("t2");
public static int i = print("i");
public static int n = 99;

public int j = print("j");

static {
print("静态块");
}

public Text(String str) {
System.out.println((++k) + ":" + str + " i=" + i + " n=" + n);
++i;
++n;
}

public static int print(String str) {
System.out.println((++k) + ":" + str + " i=" + i + " n=" + n);
++n;
return ++i;
}

public static void main(String args[]) {
new Text("init");

}
}

1:j i=0 n=0
2:t1 i=1 n=1
3:j i=2 n=2
4:t2 i=3 n=3
5:i i=4 n=4
6:静态块 i=5 n=99
7:j i=6 n=100
8:init i=7 n=101
...全文
1234 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lkj2016 2020-07-31
  • 打赏
  • 举报
回复
debug一下就行了,

50,541

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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