首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

类的初始化有关问题

2012-03-01 
类的初始化问题classCextendsB{inti1C(inti){this.iiSystem.out.println( C()siis+i)}voidrun(){Sy

类的初始化问题
class   C   extends   B
{
int   i   =   1;
C(int   i){
this.i   =   i;
System.out.println( "C()   's   i   is   "+i);
}
void   run(){
System.out.println( "C.run()     i   is   "+i);
}
public   static   void   main(String[]   args)  
{

C   c   =   new   C(10);

}
}


abstract   class   B
{
B(){
System.out.println( "B()   before   run() ");
run();
System.out.println( "B()   after   run() ");
}
  abstract   void   run();
}

大家事先预测一下打印内容,再自己编译运行一下,看看结果是不是一样,测试基本功!

[解决办法]
B() before run()
C.run() i is 1
B() after run()
C() 's i is 10

热点排行