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

📄 overloadoverride.java

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

/** A class used to demonstrate the interaction
  * among methods that are both overridden and
  * overloaded
  */
public class OverloadOverride {

   /** Test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      SubClass1 x = new SubClass1();
      x.chewGum( 2.4 );  //overriding subclass method
      x.walk( 100.345 ); //overloaded superclass method
      x.walk( 89 );      //overloaded subclass method
   }

}

/** An example superclass */
class SuperClass1 {

   public void chewGum( double x ) {
      System.out.println( "SuperClass1.chewGum(double)"
                          + " called" );
   }

   public void walk( double x ) {
      System.out.println( "SuperClass1.walk(double)"
                          + " called" );
   }

}

/** An example subclass */
class SubClass1 extends SuperClass1 {
 
   public void chewGum( double x ) {
      // override superclass function chewGum
      System.out.println( "SubClass1.chewGum(double) "
                          + " called" );
   }

   public void walk( int x ) {
      // overload superclass function walk
      System.out.println( "SubClass1.walk(int) "
                          + " called" );
   }

}

⌨️ 快捷键说明

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