add demo for how new keyword working
This commit is contained in:
parent
cc0ecc57bb
commit
103b75b80b
27
src/jvm/ObjectCreate.java
Normal file
27
src/jvm/ObjectCreate.java
Normal file
@ -0,0 +1,27 @@
|
||||
package jvm;
|
||||
|
||||
/**
|
||||
* This class is intended to demo how jvm create object and invoke constructor. Please see byte code.
|
||||
* use javap -v ObjectCreate.class or javap -c ObjectCreate.class to see byte code
|
||||
*/
|
||||
public class ObjectCreate {
|
||||
private String field;
|
||||
|
||||
// will invoked by invokespecial
|
||||
public ObjectCreate(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public void print() {
|
||||
show();
|
||||
}
|
||||
|
||||
private void show() {
|
||||
System.out.println(field);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ObjectCreate objectCreate = new ObjectCreate("hello!");
|
||||
objectCreate.print();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user