zoukankan      html  css  js  c++  java
  • 函数重载

    一、函数重载的条件:(满足其一即可)

      1)参数个数不同

      2)参数类型不同

      3)参数类型的顺序不同

      示例:

        

     1 /*函数重载条件*/
     2                 public class FunctionDemo8
     3                 {
     4                     public static void main(String[] args)
     5                     {
     6                         System.out.println(add(3.5, 6));
     7                         
     8                     }
     9                     
    10                         public static int add(int a, int b)
    11                         {
    12                             return a+b;
    13                         }
    14                         
    15                         public static double add(double a, double b)
    16                         {
    17                             return a+b;
    18                         }
    19                         public static double add(double a, int b)
    20                         {
    21                             return a+b;
    22                         }
    23                         public static double add(int a, double b)
    24                         {
    25                             return a+b;
    26                         }
    27                         
    28                         public static int add(int a, int b, int c)
    29                         {
    30                             return a+b+c;
    31                         }
    32                 }

    二、原因:

      1)调用函数实际是根据对应的函数名称去找到对应的函数入口地址,以此来进行调用

      2)而不同的函数名称对应着不同的函数入口地址

      3)函数名称的命名:

          在C语言中:函数名称实质就是当前显示的函数名
        eg:

         int
    func(int a, char b, double c); 的实际函数名称为:  func
       

      

        在java语言中:函数名称实质为:函数名_参数类型名
        eg:
        int func(int a, char b, double c); 的实际名称为:func_int_char_double

       由此,我们也知道了C语言不能有函数重载,而java语言有函数重载的原因。

        

        

  • 相关阅读:
    BZOJ3000 斯特林公式
    组合数学一些结论
    CSP2019-JS 游记(总结)
    Atcoder AGC1~10 problem list
    ioi2015hw
    NOI2017解题报告
    HNOI2021游记
    4月做题记录
    WC2021题解
    P4592 [TJOI2018]异或
  • 原文地址:https://www.cnblogs.com/SkyGood/p/3941880.html
Copyright © 2011-2022 走看看