但是你在J#下可以随便跑的(直接COPY全体覆盖在CLASS1里就行)
我看不懂
不过JAVA c#很相似的
大家可以执行以下看看输出结果
很有意思
顺便讨论以下为什么有这个结果
class Egg {
protected class Yolk {
public Yolk() { System.out.println( "Egg.Yolk()" ); }
public void f() { System.out.println( "Egg.Yolk().f()" ); }
}
private Yolk y = new Yolk( );
public Egg() { System.out.println( "new Egg()" ); }
public void insertYolk( Yolk yy ) { y = yy; }
public void g() { y.f(); }
}
public class BigEgg extends Egg {
public class Yolk extends Egg.Yolk {
public Yolk() { System.out.println( "BigEgg.Yolk()" ); }
public void f() { System.out.println( "BigEgg.Yolk().f()" ); }
}
public BigEgg() { insertYolk( new Yolk() ); }
public static void main( String[] args) {
Egg e = new BigEgg();
e.g();
}
}
[此贴子已经被作者于2006-8-18 14:35:21编辑过]