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语言有函数重载的原因。

        

        

  • 相关阅读:
    for循环,pydev提示未使用的变量,解决办法
    sc 与net命令的区别
    Selenium测试Ajax程序(转)
    Python yield 使用浅析(转)
    python操作Excel读写--使用xlrd
    Python操作Mysql实例代码教程在线版(查询手册)
    MySQL之alter语句用法总结
    使用WebDriver遇到的那些坑(转)
    python 列表转为字典的两个小方法
    python
  • 原文地址:https://www.cnblogs.com/SkyGood/p/3941880.html
Copyright © 2011-2022 走看看