动手动脑-函数重载

package qqq;

public class ww {

    /**
     * @param args
     */
    public static int square(int x)
     {
         
    return x*x;     
     }
    public static double square(double x)
     {
         
    return x*x;     
     }
    public static void main(String[] args) {
        // TODO 自动生成的方法存根

        System.out.println("the square of integer 7 is "+square(7));
        System.out.println("the square of integer 7.5 is "+square(7.5));
    }

}

以上为函数重载的运行结果,可以发现square()函数的操作数类型不同,int,double,所以函数在选择时,不会有歧义。

posted @ 2018-10-14 20:02  ZQL2017  阅读(108)  评论(0编辑  收藏  举报