论坛首页 入门技术论坛

对象初始化奇怪现象

浏览 1416 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-06-28  
直接看到代码,说答案, 执行Main后输出两行,这两行是否一样?

class A {
	{
		System.out.println(this.getClass().getName());
	}
}

class B extends A {
	{
		System.out.println(this.getClass().getName());
	}
}
public class Main {
	public static void main(String[] args) {
		new B();
	}
}


没有执行之前,我想当然的认为是不一样的,但是执行之后,令我吃惊的,居然是一样的。

估计 在父类中的this是子类的this,初始化时传递上去的。

知道的能否解释一下。
   发表时间:2009-06-28  
this.getClass()......
当然是一个东西了啊。。
0 请登录后投票
   发表时间:2009-06-28  
这么一说好像明白了
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics