Instantiate a class of steps

xiaoxiao2021-03-06  82

The step of instantification is tested. It is now summarized as follows, please correct it. 1. Allocate memory from the heap (HEAP) for example variables and other data (such as pointers to other classes and data); 2, instance variable initialization: a. First initialize the STATIC variable in the highest level of parent class, then Press the level from high to low, and finally initialize the Static variable in the current class; b. First initialize the member variables in the highest first-level parent class, then call the highest such constructor; c. Initialize the next level The member variable in the class (Non-Static), then calls such a constructor. Such push until the current class is also

Complete this. 3, the creation is complete. The test code is as follows: // Parent class: public class base {int a; {a = 3; system.out.println ("2. A =" a);} static int b; static {system.out.println "0. B =" b);} public base () {system.out.println ("3. Base");}

} // Sub-class Public Class Derived Extends Base {Public INT I; Public String S; {I = 100; S = "Fanrey"; System.out.Println ("4. S =" s);

} Static Int II; static string ss; static {ii = 10; ss = "fanrey"; system.out.println ("1. Ss =" ss);

Public Derived () {system.out.println ("5. derived"); system.out.println ("================================================================================================================================================================================================================== == "); system.out.println (" s = " s); system.out.println (" i = " i); system.out.println (" ss = " ss); system.out .println ("II =" II); system.out.println ("============================");

Public static void main (string [] args) {derived d = new derived ();

}} Run results: 0. B = 0

SS = Fanrey

2. a = 3

3. Base4. S = fanrey

5. Derived

===========================

s = fanrey

i = 100

ss = fanrey

II = 10

===========================

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

New Post(0)