Learning notes: Java initialization order

xiaoxiao2021-03-06  93

Class bowl {bowl (int marker) {system.out.println ("Bowl (" ")") ");} void f1 () {system.out.println (" OK, QQ: 12953091 ");}} Class Cupboard {Bowl B1 = New Bowl (1); Static Bowl B2 = New Bowl (2); Cupboard () {System.out.Println ("Cupboard ()");} static bowl b3 = new bowl (3); } Class table {table () {system.out.println ("Table ()" 1048155)} Table (String A, INT i) {this (); system.out.println ("ok" 23387612);} PUBLIC CLASS ORDER = New Cupboard (); Static Table T2; Bowl T3 = New Bowl (10); void print () {t3.f1 ();} public static void main (String [] args) { System.out.println ("Creating New Cupboard () in main"); new cupboard (); System.out.Println ("Creating new curnet () in main"); Order Od = new order (); od.t3 .f1 (); table t4 = new table ("aa", 1);}}

ORDER.CLASS, run the Order.class, run the Static block Static CupBoard T1 = New Cupboard (); this constructs a Cupboard object, when constructing the object, the Cupboard class is loaded, and the Static block Static Bowl B2 = New Bowl (2); // Create a Bowl object, the process and Cupboard, call the constructor static bowl b3 = new bowl (3); //, then execute Bowl B1 = New Bowl (1); // Create a Bowl object then performs constructor Bowl () Next: Static Table T2; // This is just a declaration, doesn't create an object, don't pay attention to: Execute the statement in the main function System.out.println ("CREATING New Cupboard () in "); new cupboard (); // Note that static only initializes system.out.println (" CREATING CUPBOARD () in main "; Order OD = new order (); // Create an Order object同 同 上 o t ("aa", 1); // Create Table, note that call this () can be overloaded here (need to be overloaded)

转载请注明原文地址:https://www.9cbs.com/read-102617.html

New Post(0)