码迷,mamicode.com
首页 > 其他好文 > 详细

主函数调用相同函数名的小知识

时间:2016-10-16 11:55:56      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

// MethodOverload.java
// Using overloaded methods

public class MethodOverload {

 public static void main(String[] args) {
  System.out.println("The square of integer 7 is " + square(7));
  System.out.println("\nThe square of double 7.5 is " + square(7.5));
 }

 public static int square(int x) {
  return x * x;
 }

 public static double square(double y) {
  return y * y;
 }
}

 在JAVA中,函数名字相同,返回类型不同是允许的,在调用过程中,调用int还是double取决于函数square()括号里的参数是int还是double,在调用相应函数。

主函数调用相同函数名的小知识

标签:

原文地址:http://www.cnblogs.com/shouhutian/p/5966151.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!