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