方法重载

方法重载:

  ···在一个类中,方法的名字可以相同,参数列表必须不同(类型不同、个数不同、顺序不同),与返回类型无关,构成方法的重载

 1 class Method15{
 2     //总结:在一个类中,方法的名字可以相同,参数列表必须不同(类型不同、个数不同、顺序不同),与返回类型无关,构成方法的重载
 3     //练习13:使用方法完成,获取两个数中的最大数
 4     public static int max(int a,int b){
 5             return a > b?    a :     b;
 6     }
 7     public static void max(double x,int y){
 8             System.out.println(x > y? x : y);
 9     }
10     public static void max(double x,double y){
11             System.out.println(x > y? x : y);
12     }
13     public static void main(String[ ]args){
14         System.out.println(max(10,12));
15         System.out.println(max(103,12));
16         max(0.9,13);
17         max(13.3,12.9);
18     }                                          
19 }

                         

posted @ 2019-05-16 21:43  Penphy  阅读(168)  评论(0编辑  收藏  举报