The process by which the JVM loads a class instantiation

Source: Internet
Author: User
<span style= "FONT-SIZE:32PX;" > Subclass a inherits the parent Class B, a A = new A (); The order in which the parent Class B constructor, parent class B static code block, parent Class B non-static code block, subclass a constructor, subclass a static code block, subclass a non-static code block executes.
correct answer: C  

A parent class B static code block-> Parent Class B constructor-> subclass a static code block-> parent Class B non-static code block-></span>
<span style= "FONT-SIZE:32PX;" > Subclass a constructor-> subclass a non-static code block
B parent Class B static code block-> Parent Class B constructor-> parent class B non static code block-> subclass a static code block-></span>
<span style= "FONT-SIZE:32PX;" > Subclass a constructor-> subclass a non-static code block
C Parent Class B static code block-> subclass a static code block-> parent Class B non-static code block-> Parent Class B constructor-></span>
<span style= "FONT-SIZE:32PX;" > Subclass a non-static code block-> subclass a constructor
D parent Class B constructor-> parent Class B static code block-> parent Class B non-static code block-> subclass a static code block-></span>
<span style= "FONT-SIZE:32PX;" > Subclass a constructor-> subclass a non-static code block </span>


This problem, you can't understand the process of JVM instantiation object,

We're going to list this process:

1 The virtual machine first needs to load the. class file and load it into memory, and it will load the parent class of the instance (if the instance has a parent class, we have a parent class for good explanation)

2 Open space in heap memory, assign address

3 is then initialized with the attributes in the object.

4 The corresponding constructor is initialized

5 in the constructor, the parent class is initialized first

6 The Subclass property is initialized after the parent class initialization is complete

7 Subclass constructor to initialize

8 when initialization is complete, assign the address value to the reference variable.

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.