函数重载

同一个类中函数名字相同但参数不同的现象,一般称为函数重载。

为什么需要函数重载呢?一般是因为函数想表达的意义是一样的,但函数个数或类型不一样。

比如,求两个数的最大值,在java的Math库中就定义了四个函数:

Math库的四个max函数.pngMath库的四个max函数.png

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
Powered By Valine
v1.4.14
  • Copyrights © 2021 Silver Shaded
  • Visitors:3136 | Views:5168

请我喝杯咖啡吧~

支付宝
微信