方法重载

 1 package com.baidu.day04;
 2 //方法重载:功能类似的方法实现重载
 3 //函数名相同,形参列表不同(与函数的返回值无关)
 4 //比较2个数是否相等,参数分别byte,int,long
 5 public class Overload {
 6     public static void main(String[] args) {
 7         /*System.out.println(sum(2,3));
 8         System.out.println(sum(2,3,4));
 9         System.out.println(sum(2,3,4,5));*/
10         System.out.println(chose((byte)2,(byte)3));
11     }
12     public static boolean chose(byte a,byte b){
13         System.out.println("byte");
14         return a==b;
15     }
16     public static boolean chose(int a,int b){
17         return a==b;
18     }
19     public static boolean chose(long a,long b){
20         return a==b;
21     }
22     /*public static int sum(int a,int b){
23         return a+b;
24     }
25     public static int sum(int a,int b,int c){
26         return a+b+c;
27     }
28     public static int sum(int a,int b,int c,int d){
29         return a+b+c+d;
30     }*/
31 }
32 --------------------------------------------------------
33 byte
34 false
35 
36 Process finished with exit code 0

a.方法即函数,实现某特定功能的代码块
b.方法定义在类中,不能在方法中定义方法,方法定义的前后顺序无所谓
c.方法重载:函数功能类似可重载方法-----函数名相同,参数列表不同(与返回值无关):
  参数个数不同,参数类型不同(与形参的名称无关)

posted @ 2019-03-14 22:44  超人不会飞0  阅读(277)  评论(0编辑  收藏  举报