Call the processing steps of the constructor

original
2014/08/07 16:07
Reading number 264
Specific processing steps of calling the constructor:

1) All data fields are initialized to default values (0, false, null)
2) Execute all domain initialization statements and initialization blocks in the order they appear in the class
3) If the first line of the constructor calls the second constructor, the second constructor body is executed
4) The body that executes this constructor

 public class TestConstructLoad { public static void main(String[] args) { new ConstructorLoad(1); } } class ConstructorLoad { //1. All data fields are initialized to default values (0, false, null) private int a; private String b = "xxxxxxxxx"; //2. Execute all domain initialization statements and initialization blocks in the order they appear in the class { System. out. println ("initialization block a="+a+", b="+b); a = 10; } //3. If the first line of the constructor calls the second constructor, execute the second constructor body public ConstructorLoad() { System. out. println ("ConstructorLoad has no parameters"); } //4. The body executing this constructor public ConstructorLoad(int a) { this(); System. out. println ("ConstructorLoad has parameters, a="+this. a+", b="+this. b); this.a = 20; } }




Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
one Collection
zero fabulous
 Back to top
Top