Class fuck {static {system. out. println ("this is static");} public fuck () {system. out. println ("this is gozao");} public void S () {system. out. println ("this is parent") ;}} public class test08 extends fuck {public static void main (string [] ARGs) {fuck d = new fuck (); D. S (); Fuck SV = new test08 (); Sv. S ();} public void S () {system. out. println ("this is Son ");}}
The above is a typical interview instance, also as a JavaProgramYou must have a basic understanding of the instance. My summary of the above example is as follows:
1. Whoever calls New: when using the new keyword to create an instance of the class, the method used to call this instance must be the method used to call this class. If this method is not available in this class, calling the parent class method is an inevitable choice.
2. initialize the parent class before initializing the subclass. When you use the new keyword to create a specific instance of a class, you usually need to initialize the class first. However, if the class has a parent class, you must initialize the parent class first. The so-called Initialization is to call the constructor.
3. the initialization class has the following sequence: (1) variable (2) staticCodeBlock (3) Call constructor Initialization
The results can be imagined as follows:
This is staticthis is gozaothis is parentthis is gozaothis is Son