阿里巴巴的笔试题,请大神给我解释下n的值。

tianmu_1991 2013-10-06 11:58:51
请写出下面程序的输出:
public class Test {
public static int k=0;
public static Test t1=new Test("t1");
public static Test t2=new Test("t2");
public static int i=print("i");
public static int n=99;
public int j=print("j");
{
System.out.print("构造块");
}
static{
System.out.print("静态构造块");
}
public Test(String string) {
System.out.println((++k)+":"+string+" i="+i+" n="+n);
++i;++n;
}
private static int print(String string) {
System.out.println((++k)+":"+string+" i="+i+" n="+n);
++n;
return ++i;
}
public static void main(String[] args) {
new Test("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:j i=5 n=99
构造块7:init i=6 n=100
我的答案n的值是从99-105,求解释一下,谢谢啊 分不多了啊.
...全文
116 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianmu_1991 2013-10-06
  • 打赏
  • 举报
回复
好吧.受教了....
ifvlr 2013-10-06
  • 打赏
  • 举报
回复
第四次出现在该论坛上了,加上2008年那一次,我统计的应该是第五次了。。。 第一次 http://bbs.csdn.net/topics/390597457 第二次 http://bbs.csdn.net/topics/390605401 第三次 http://bbs.csdn.net/topics/390606269 你这是第四次问。。。 这个题在2008年的时候就有人问了。。还是被加了精华的帖子 http://bbs.csdn.net/topics/280036316 关于这个题,我你应该先搜索一下帖子再问。。。

62,614

社区成员

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

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