Knowledge points and recursive invocation of methods in Java

Source: Internet
Author: User

Method Execution principle : ( The method does not call do not execute, the call executes )
* Method will divide the space in memory only when it is called
* method is allocated in the stack memory at the time of the call (the JVM has a chunk of memory is the stack memory)

* Function/method purpose : or for code reuse
* Same type of operation, no duplication of write code
* Function/method : A code snippet with a name

* Definition of method
* [ method modifier list ] method returns a value type method name ( parameter 1, parameter 2, Parameter 3...) {
* EXECUTE statement;
 *  }
 *
* method modifier list is optional : Permissions controlled by: public protected private/static
* return value type : 11 Any one of the types in the data type
* no return value on :void
* Method name as long as it is a valid identifier
* Method parameter list, multiple comma separated, formal parameter also to indicate data type;
* Formal parameter: refers to the function/method definition, those parameters; Data type variable name, data type, variable name,
* argument: refers to the parameter passed in at the function call.
* Inside the method body, if there is a return value (type), with a return statement, and return is the function of the end
* method invocation : From the memory data structure is the compression stack
* The end of the method : from the memory data structure is the bomb stack

* Overloading of methods :
* In the same class, the method name is the same, the parameter list method is called the method overload;
* parameter list is different: can be different number of parameters, can be different parameter data type
* method overloads and return values, regardless of the modifier list.
* Stack : This XI. data structure, like a magazine, a potato chip box, go first.

The following is an example of recursive invocation:

Public class method_10{
Public static void Main (string[] args) {Method Main Entrance
int i=100;Declaring data type I, assigning a value of 100
m_1 (i);Call the M1 method, assign I to 100
System.out.println ("Hello World");Completion of assignment after calling M1, output content
}
Public static void M1 (int i) {Declaring the M_1 method
m_2 (i);Call the M_2 method, I is assigned a value of 100
System.out.println ("method m_1 is called");//Operating principle:The M_1 method calls the M_2, declares the M_2 method and calls the method M_3, declares the method m_3, exports m_3 in M3 i= in the output +i, the output is called, I is assigned to M_3 after the run is returned to call 100,m_3, in the M_3 declaration, the m_2 call runs complete , the output method m_2 is called; after M_2 run, return to call m_2, in declaration m_1, m_2 run complete, output "method m_1 called", Return to call m_1, output "Hello word"
  }
Public static void m_2 (int i) {
M_3 (i);
System.out.println ("method m_2 is called");
        
    }
Public static void m_3 (int i) {

System.out.println ("i= in the M_3 method" + i);
System.out.println ("method M_3 is called");
    }
}

This is what I have just learned, the impression is more profound, so summarize, recorded, convenient to view later, this article is my understanding of the written down, there is nothing wrong place also hope and everyone more exchanges, O (∩_∩) o Thank you!

Knowledge points and recursive invocation of methods in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.