动手动脑兼课后作业2

MethodOverload:

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

我发现两个函数又相同的名字,但是他们的输入和输出都是不同的,这是函数的重载。

猜你喜欢

转载自www.cnblogs.com/jiaoaoshirenjinbu/p/11595702.html