Java Surface Question Series (iii) What happened in the process of Java new object

Source: Internet
Author: User

Person

classperson{PrivateString name; Private intAge ;  PublicPerson () {Super(); }      PublicPerson (String name,intAge ) {         This. Name =name;  This. Age =Age ; }      PublicString GetName () {returnname; }      Public voidsetName (String name) { This. Name =name; }      Public intGetage () {returnAge ; }      Public voidSetage (intAge ) {         This. Age =Age ; } @Override PublicString toString () {return"Person [name=" + name + ", age=" + Age + "]"; }}

New

 Public class newobjecttest {    publicstaticvoid  main (string[] args) {                  New person ("Zhang San");        System.out.println (P.tostring ());            } }

The first thing to be clear is that after the compilation is complete, the folder will Newobjecttest.class and Person.class two class files

The JVM reads the main method entry and finds the person P = new person ("Zhang San", 18); The sentence that needs a new object (not really, the JVM reads only the bytecode in class), and then does the following:

1. Load the Person.class file into the method area and load the static property in the person class

2. Assign a reference (reference) p to the stack where the main method resides;

3. Open space in the Java heap to store the person class, but not initialize the operation.

4. Default initialization of data

5. Point the reference p to the newly opened person class in Java

Https://www.cnblogs.com/JackPn/p/9386182.html

80530530

Java Surface Question Series (iii) What happened in the process of Java new object

Related Article

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.