public class Test184 extends c184 {
private a184 at = new a184("a in t");
private int i = f(); Test184() {
System.out.println("this is test184");
} public int f() {
System.out.println("this is t f()");
return 1;
} public static void main(String[] args) {
Test184 t = new Test184();
}}class a184 {
a184(String s) {
System.out.println("this is a.." + s);
}
}class b184 {
private a184 ab = new a184("a in b"); b184() {
System.out.println("this is b..");
}
}class c184 extends b184 {
private a184 ac = new a184("a in c"); c184() {
System.out.println("this is c..");
}
}
运行结果:
this is a..a in b
this is b..
this is a..a in c
this is c..
this is a..a in t
this is t f()
this is test184请问下红色部分为什么不先被初始化呢?
解决方案 »
- 求高手指点下方案 关于服务器共享文件的问题
- 字符流中read方法返回值是int,为什么输出是char?
- 请问"static"是什么意思?
- 菜鸟求助局部变量初始化的问题?
- 急在线等,一个简单的问题
- Eclipse插件系列操作说明手把手教你使用SQLExplorer、Implementors、Bytecode Outline、Hidden Heap Status、EasyExplorer
- [求助]请高手帮我解释一下(线程的运行过程问题)
- 关于JDK设置的问题,麻烦大家帮帮忙,急
- JAVA与C++关于JNI中文字符串操作问题???
- 子类能不能继承父类里protected的内部类
- 一个java组件的paint方法的问题
- jdbc连接oracle产生ORA-12505 异常
要实例化Test184需实例化c184,实例化c184需要实例化b184
实例化b184需先要初始化实例变量ab
class b184
{ b184()
{
ab = new a184("a in b");
System.out.println("this is b..");
} private a184 ab;
}
b184实例化后再实例化c184
同理需要初始化实例变量ac
class c184 extends b184
{ c184()
{
ac = new a184("a in c");
System.out.println("this is c..");
} private a184 ac;
}
最后实例化Test184初始化实例变量
at,i
public class Test184 extends c184
{ Test184()
{
at = new a184("a in t");
i = f();
System.out.println("this is test184");
} public int f()
{
System.out.println("this is t f()");
return 1;
} public static void main(String args[])
{
Test184 test184 = new Test184();
} private a184 at;
private int i;
}
明白不明白其中的代码是我用反编译工具反编译的.不理解还可以再问
是不是我这样理解错的?
public class Test184 extends c184 {
private a184 at = new a184("a in t");
private int i = f(); Test184() {
a184 at1 = new a184("a in t..Test184()");
System.out.println("this is test184");
} public int f() {
System.out.println("this is t f()");
return 1;
} public static void main(String[] args) {
Test184 t = new Test184();
}}class a184 {
a184(String s) {
System.out.println("this is a.." + s);
}
}class b184 {
private a184 ab = new a184("a in b"); b184() {
System.out.println("this is b..");
}
}class c184 extends b184 {
private a184 ac = new a184("a in c"); c184() {
System.out.println("this is c..");
}
}
那我要是在Test184类构造器中再放个变量呢?他是什么时候被初始化?
谢谢大哥们了~~
this is b..
this is a..a in c
this is c..
this is a..a in t
this is t f()
this is a..a in t..Test184()
this is test184