Java class loading, invoking constructors, executing method procedures

Source: Internet
Author: User

Note: In this part of the knowledge point to find a lot of problems have not been clear, so there may be many less detailed or even wrong understanding, ready to turn over the programming ideas to update,

Welcome to comment Exchange

When the JVM executes a code like this: New person (). SetName ("Superzhao")

It will do so a few things

Class loading

The JVM will load the class file Xxx.person with the ClassLoader.

Load (Class) {

if (class has parent) {

Load (superclass);

}

1. static domain declaration, default initialized to 0,false,null

2. Perform static domain (Assignment) and static code block (execute code block body) in order of declaration (top down order)

    The two are equivalent, so the static domain that is declared after the code block cannot be used in a static code block, but can be initialized

3. Loading static methods in order of declaration

}

constructor is called (object initialization)

1. All instance domains are initialized to default values 0,false,null

2. Perform domain initialization and block initialization in the order of declaration

3. If the constructor "first row" calls a different constructor, execute the

4. Executing the constructor body

Calling methods

1. The compiler looks at the declaration type of the object and finds all of its methods with the same method name

2. Depending on the type of the parameter, it is possible to find the appropriate "most appropriate" parent method for the type conversion (upward transformation)

3. If it is a private,static,final, constructor method, then it is determined that this method (these four types of methods do not have polymorphic characteristics),

Because there is no polymorphism, it is also called static binding.

4. In other ways, use dynamic binding: The JVM is looking for the most appropriate method for the actual type of the change class.

5. Execute the call

Java class loading, invoking constructors, executing method procedures

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.