OOP面向对象编程(一)-------方法的重载

面向对象之重载:
* 方法的重载(overload)
* 1.方法在同一个类中
* 2.方法名需要相同
* 3.方法的参数列表不同----参数个数不同/参数个数相同,但是参数类型不同
* 补充:方法的重载与方法的返回值类型没有关系

练习代码:
 1 public class OOPOverLoad {
 2     public static int add(int a,int b){
 3         return a+b;
 4     }
 5     public static double add(double a,double b){
 6         return a+b;
 7     }
 8     public static int add(int...a){
 9         int s = 0;
10         for (int i = 0; i <a.length ; i++) {
11             s = s+a[i];
12         }
13         return s;
14     }
15 
16     public static void main(String[] args) {
17         System.out.println("调用add(int,int)的方法"+add(1,2));
18         System.out.println("调用double(int,int)的方法"+add(1.0,2.0));
19     }
20 
21 
22 }
原文地址:https://www.cnblogs.com/yaoruozi/p/8561522.html