1. The following code cannot be compiled, where is the error?
Cause: Because the constructor foo () is not defined, if the class provides a custom construction method, the default construction method is no longer provided by the system.
:
2. Please summarize the rule of Java field initialization according to the output result of the code.
Output Result:
Summarize the rules of Java field initialization: Java field initialization rules the system initializes the Java fields sequentially, and if there are several methods that initialize the same variable. Java assigns the last initialization result to the variable.
3. Hands-on brain: Run the Teststaticinitializeblock.java example, observe the output, and summarize the "Order of execution of static initialization blocks"
Static initialization blocks are executed only once. When you create an object of a subtype, it also causes the execution of the static initialization block of the parent type.
4. Static methods only allow access to static data, so how to access instance members of a class in a static method (that is, a field or method that does not have a static keyword attached)
Please write code to verify your idea
5. Using the class's static fields and constructors, we can track the number of objects created by a class. Write a class that can query it at any time "how many objects have you created?" ”。
Class and object hands-on brain