java study notes - Overload

myJavaNotes Package Penalty for;

/ **
 * @ author Kang Dad
 * @ date: 2020 January 24 morning 02:17:38
 *
 * /
public class MethodOverloading {

    public static void main (String [] args) {
        // TODO Auto- method Stub Generated

        / * method: snippet period to accomplish a particular function, function similar to other languages
          method declaration format:
          [modifier modifier 1 2 ....] return type method name (formal parameter) {
                  Java statement block;
                  ......
          }
          
          method call:
          Object name method name (the actual parameter list)
          
          
          
         * * /
        
        / * formal parameters: the number for receiving incoming outside in the method declaration
         * actual parameter: calling methods the actual data when passed to the method
         * return value: returns after the implementation of the method to invoke its environment data
         * return value: a pre-agreed return value data types, such as: no return value must be displayed either void
         *
         * * /
        
        // object call by an ordinary method: a new class is needed to object by calling the object method

        MethodOverloading mol MethodOverloading = new ();
        int mol.add SUM1 = (1,2); // with the first new class objects , by calling the object method
        System.out.println (SUM1);
        
        int sub RESULT1 = (5,2); // call sub overloaded method 1; direct method call sub (public static method name (parameter) {} block of statements )
        System.out.println (RESULT1);
        
        int sub result2 = (7,2,6); // call sub overloaded method 2
        System.out.println (result2);
        
        Double sub result3 = (4.2,5.7); / / sub overloaded method call. 3
        System.out.println (result3);
        
        / * Note
        1, the number of arguments, the type and order of data must be declared parameter list of a method called consistent
        2, the method java when the call transfer parameters, follow the principle of (copies of data are transmitted) value passed
        copy value 3, the basic type of data transfer value
        4, reference copy when the value of the object reference type of transmission, but just the same object;
        
        * /
    
    
    / * Method overloading:
      actually a completely different method, the same method name knowledge (easy to use, the intentional use of the same name)
    
       configuration overload conditions:
      1, parameter type, parameter number, a different sequence parameter
      2, not only return a different value constituting overloaded methods
      such as: int a (String str) { } and void a (String str) { overload} does not constitute a method
      3, only the different parameter name, does not constitute a method of overload:
      as: int a (String str) { } and int a (String s) {} does not constitute an overloaded method
     * * /
    
    
    
    
    
    
    
    
    }
    // method declarations and definitions: no add static declaration and define a method, you need to call through the new object.
    the Add int (int A, int B) {
        int SUM = A + B;
        return SUM; // return role: 1, the end of the method of operation; 2, returns a value
    }
    
    // Overload sub Method 1
    public static int sub (A int, int B) {
        int Result = ab &;
        return Result;
    }
    // overload sub Method 2, the same (as compared to 1) the method name, number of different parameters, reload configuration
    public static int sub (A int, int B, int C) {
        
        int Result = ABC;
        return Result;
    }
    // overload sub method 3, the same (as compared to 1) the method name, parameters of different types, constituting overloaded
    public static Double sub (Double A, Double B) {
        
        Double Result = ab &;
        return Result;        
    }
    
}

Guess you like

Origin www.cnblogs.com/destiny-2015/p/12233666.html