第二次课堂测试2

1.重载函数

代码:

 1 // MethodOverload.java
 2 // Using overloaded methods
 3 
 4 public class MethodOverload {
 5 
 6     public static void main(String[] args) {
 7         System.out.println("The square of integer 7 is " + square(7));
 8         System.out.println("\nThe square of double 7.5 is " + square(7.5));
 9     }
10 
11     public static int square(int x) {
12         return x * x;
13     }
14 
15     public static double square(double y) {
16         return y * y;
17     }
18 }

 程序思想:用重载函数实现不同类型的数据类型的平方计算。

程序收获:重载函数有三种重载方式:1.形参类型重载  2.形参个数重载  3.形参顺序重载。

猜你喜欢

转载自www.cnblogs.com/w669399221/p/11599760.html
今日推荐