• JavaSE复习日记 : 方法的调用和方法的重载


    /*
     *                          方法的调用和方法重载
     */
    
    /*
     *      什么是方法?
     *          方法就是一个有名字的代码段;
     *      方法的调用:
     *          在方法里调用另外一个方法里面的东西就是方法调用;
     *          或者可以认为"另外一个方法的名字()"就是方法的调用;
     *      方法的重载:
     *          就是在main方法外写了多个方法名相同,但是形参列表不同的方法,在main方法中调用这个方法时括号内写上实参,程序会默认调用实参和调用方法里形参相匹配的方法;
     */
    
    //                              方法形式和方法的类部调用
    
    /*
    public class JavaSE{
        public static void main(String[] args){
            JavaSE.Method_1();//方法的调用就是:类名.方法名(实参列表);
            Method_2(1,2);//main方法调用这个类里面的静态方法也可以这么写;
            Method_3(5,5);
        }
        public static void Method_1(){
            System.out.println( "我很帅" );
        }
        public static void Method_2(int a,int b){
            int c = a + b;
            System.out.println( c );
        }
        public static int Method_3(int e,int d){//注意这里static后面跟的是int,是返回值类型,这是方法最后必须写return语句;
            int f = e + d;
            System.out.println( f );
            return f;//return语句在有返回值类型的时候必须有返回值,不然会报错;
        }
    }
    */
    
    //-------------------------------------------------------------------------
    
    //                          方法的重载
    
    public class JavaSE{
        public static void main(String[] args){
           Method_4(1,1.0);//这里1是int型的,1.0是double型的,结果是2.0,结果自动转换为double型
           Java.sum(2,1);//调用外部类的方法必须是:外部类名.方法名(实参列表);
        }
        public static void Method_4(int a,int b){
            int c = a + b;
        }
        public static void Method_4(int a,double b){
            System.out.println( a + b );
        }
    }
    
    class Java{
        public static void sum(int a,int b){
            System.out.println( a + b );
        }
        public static void sum(int a,double b){
            System.out.println( a - b );
        }
    }

     >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>杰我教育WWW.JAOVO.COM<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

  • 相关阅读:
    poj 3666 Making the Grade
    poj 3186 Treats for the Cows (区间dp)
    hdu 1074 Doing Homework(状压)
    CodeForces 489C Given Length and Sum of Digits...
    CodeForces 163A Substring and Subsequence
    CodeForces 366C Dima and Salad
    CodeForces 180C Letter
    CodeForces
    hdu 2859 Phalanx
    socket接收大数据流
  • 原文地址:https://www.cnblogs.com/yizhimichong/p/4751287.html
Copyright © 2020-2023  润新知