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

📄 testmethodoverloading.java

📁 此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码。
💻 JAVA
字号:
// TestMethodOverloading.java: Demonstrate method overloading
public class TestMethodOverloading
{
  // Main method
  public static void main(String[] args)
  {
    // Invoke the max method with int parameters
    System.out.println("The maximum between 3 and 4 is "
      + max(3, 4));

    // Invoke the max method with the double parameters
    System.out.println("The maximum between 3.0 and 5.4 is "
      + max(3.0, 5.4));

    // Invoke the max method with three double parameters
    System.out.println("The maximum between 3.0, 5.4, and 10.14 is "
      + max(3.0, 5.4, 10.14));
  }

  // Find the max between two int values
  static int max(int num1, int num2)
  {
    if (num1 > num2)
      return num1;
    else
      return num2;
  }

  // Find the max between two double values
  static double max(double num1, double num2)
  {
    if (num1 > num2)
      return num1;
    else
      return num2;
  }

  // Find the max among three double values
  static double max(double num1, double num2, double num3)
  {
    return max(max(num1, num2), num3);
  }
}

⌨️ 快捷键说明

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