Detailed methods

The attributes for the methods
in the Java language, the method can not exist, the method must belong to the class or object.
Therefore, if the definition of the method, the body can only define a class, a method can be defined independently. Once a method is defined in the body of a class-based, if the method uses a static modification, then this method belongs to the class, otherwise this method belong to the class of this instance

(Using a modified static method belongs to the class itself, using a modified static method not only can use the class as the caller to call, you can also use the object as the caller to call. It is worth noting that the use of static modification of the method still belongs to the class will thus get the same effect when performing this method is used to invoke any object class, since the underlying instances of these classes is still used as the caller belongs)
(not modified static method belongs to an object class, does not belong to the class itself. So there is no static method can only be modified using an object as the caller to call, as the caller can not be used to call the class using different objects as the caller to call the same general method, you may get a different results.)

parameter passing mechanism of the
Java method call must also be used as the main theme of the class or object person. If the parameter declaration contains the method declaration must specify parameter values for these parameters form when calling the method, the actual parameter value passed when calling the method parameter is also referred to as arguments.
How Java argument value is passed to the method? This is actually a Java method parameter passing mechanism to control, parameter passing method in Java is only one method: value is passed. The so-called value is passed, it is a copy of the actual parameter values (replica) passed within the method, and the parameter itself will not be affected.

(Java in the parameter passing like "Journey to the West" in the Monkey King, Sun Wukong the Monkey King copy of a fake, the fake Monkey King and the Monkey King has the same capabilities. But no matter what the fake encounter the Monkey King, the Monkey King will not suffer any real Effects.)
of variable shape parameter method number
recursive method
a call to his own vivo method, the method is called recursively. The method comprises a recursive loop implicit, it will repeat the piece of code, but this cycle is repeatedly performed without control.
Method overloading
Java allows the same class of the same name defined in the method, different parameter list as long as the line. If the same includes two or more methods of the same class method names, but with different parameter list, is called method overloading
method overriding requirement is that a different two identical: the same class the same method name , different parameter list. As for the other part of the method, as a method return type, modifier, etc., without any relationship with method overloads.

(Why the return value type can not be used in the method of distinguishing overload?
For int f () {} and void f () {} two methods, if called
int result = f () ;, the system may identify a call int return type of the method;? but you can ignore Java method returns a value when calling the method, if to call f () ;, you can use the following method to determine which method is what if you can not judge yet, the system will then Java Fuzzy programming has an important rule: Do not let the system confused, confused a system, given that it is their mistake and therefore, java in return type can not be used as a basis to distinguish overloaded methods to use).

Published 47 original articles · won praise 12 · views 7252

Guess you like

Origin blog.csdn.net/weixin_43717681/article/details/103070152