⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alteredbinding.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package examples.inheritance;

/** A class used to demonstrate how dynamic
  * binding can be altered by using the
  * <b>super</b> reference.
  */
public class AlteredBinding {

   /** Test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      D x = new D();
      x.g1();
      x.g2();
   }

}

/** An example super class */
class B {

   public void f( String caller ) { 
      System.out.println( "B.f() called by "
                          + caller );
   }

}

/** An example subclass */
class D extends B {

   public void f( String caller ) {
      System.out.println( "D.f() called by "
                          + caller );
   }

   public void g1() {
      f( "subclass" );       // this will call D.f()
   }

   public void g2() {
      super.f( "subclass" ); // cannot use B.f() here
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -