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