2019.9.23JAVA hands-on brain

1 Consider the following code, you find what is special about it?

// 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;
 }
}
 Found: method overloading name is defined in the same manner, however the order parameter, the number, the three least one of a different type, as an example when two parameters must be in a different order when the double overload after a double int int, but int int, double double or exchange order is not overloaded, the method returns reload different types of values ​​will not be considered, because, for example, when the above code, the method call returns a value of type is not, so if other are the same but return value types are different, the computer does not know what to call, so the return value of different types are not identified as overloaded.
 
 
 
 
 
Exercise 2:
  look at the JDK System.out.println () method, what have you found?
Found System.out.println () output to a variety of content is actually overloaded to System.out.println () method.
 
 
 
 

Guess you like

Origin www.cnblogs.com/tkg1314/p/11583373.html