Check the program, if there is a problem, if there is an indication of the problem, if it does not exist, the output.
Public classHellobextendsHelloa { PublicHellob () {} {System.out.println ("I ' M B class"); } Static{System.out.println ("Static B"); } Public Static voidMain (string[] args) {NewHellob ();}}classhelloa{ PublicHelloa () {} {System.out.println ("I ' M A class"); } Static{System.out.println ("Static A"); }}
A.static a class static B class
class class static A static B
C.static A static B class Class
class Static A class Static B
Answer: C.
Parsing: It involves: static initialization of code blocks, construction of code blocks, construction methods
When it comes to inheritance, it is executed in the following order:
1. Execute the static code block of the parent class
static {
System.out.println ("Static A");
}
Output: Static A
2, execute the subclass of static code block
static {
System.out.println ("Static B");
}
Output: Static B
3. Executing the construction code block of the parent class
{
System.out.println ("I ' M A class");
}
Output: I ' M A class
4. Execute the constructor of the parent class
Public Helloa () {
}
Output: None
5. Construct code block for sub-class execution
{
System.out.println ("I ' M B class");
}
Output: I ' M B class
6. Execute the Subclass constructor
Public Hellob () {
}
Output: None
Then, the final output is:
Static A
Static B
I ' M A class
I ' M B class
Correct answer: C
Java easy-to-debug title (1)