打字猴:1.700441714e+09
1700441714
1700441715 @Override
1700441716
1700441717 public int strong(){
1700441718
1700441719 //儿子比父亲强壮
1700441720
1700441721 return super.strong()+1;
1700441722
1700441723 }
1700441724
1700441725 @Override
1700441726
1700441727 public int kind(){
1700441728
1700441729 return new MotherSpecial().kind();
1700441730
1700441731 }
1700441732
1700441733 private class MotherSpecial extends MotherImpl{
1700441734
1700441735 public int kind(){
1700441736
1700441737 //儿子温柔指数降低了
1700441738
1700441739 return super.kind()-1;
1700441740
1700441741 }
1700441742
1700441743 }
1700441744
1700441745 }
1700441746
1700441747 儿子继承自父亲,变得比父亲更强壮了(覆写父类strong方法),同时儿子也具有母亲的优点,只是温柔指数降低了。注意看,这里构造了MotherSpecial类继承母亲类,也就是获得了母亲类的行为方法,这也是内部类的一个重要特性:内部类可以继承一个与外部类无关的类,保证了内部类的独立性,正是基于这一点,多重继承才会成为可能。MotherSpecial的这种内部类叫做成员内部类(也叫做实例内部类,Instance Inner Class)。我们再来看看女儿类,代码如下:
1700441748
1700441749 class Daughter extends MotherImpl implements Father{
1700441750
1700441751 @Override
1700441752
1700441753 public int strong(){
1700441754
1700441755 return new FatherImpl(){
1700441756
1700441757 @Override
1700441758
1700441759 public int strong(){
1700441760
1700441761 //女儿的强壮指数降低了
1700441762
1700441763 return super.strong()-2;
[ 上一页 ]  [ :1.700441714e+09 ]  [ 下一页 ]