// Insect. Class Package test;Class insect { Int I = 9; Int H = Y1; Static int Y1 = 8; Int J; Insect (){ PRT ("I =" + I + ", j =" + J ); J = 39; } Static int X1 = PRT ("static insect. X1 initialized "); Static int PRT (string s ){ System. Out. println (s ); Return 47; } } // Beetle. Class Public class beetle extends insect { Int K = PRT ("beetle. K initialized "); Beetle (){ PRT ("k =" + k ); PRT ("J =" + J ); } Static int X2 = PRT ("static beetle. X2 initialized "); Public static void main (string [] ARGs ){ PRT ("beetle constructor "); Beetle B = new beetle (); } } /* 1. First, try to access beetle. Main (). This is a static method. * 2. Go outside and find the code beetle. Class compiled for the beetle class. * 3. Beetle is found to have a base class during beetle. class loading. * 4. Initialize base class * 1) initialize static * 2) initialize common variables in the text order. * 5. Initialize a derived class * 1) initialize static * 2) initialize common variables in the text order. * 6. Execute the main program in main (in the text order) * 1) PRT ("beetle constructor "); * 2) instantiate a derived class (beetle B = new beetle ();) * 1) base class Constructor * 2) constructor of the derived class * * Test site: static variable initialization and access; use of Constructors **/ |