How to understand: if there are constant attributes in the parent class, the class loading of the parent class will not be performed when constant attributes are used in the subclass.

  java, question

Is it because the parent class generates constants when compiling, while the subclass already has constants when using them, so there is no need to load the parent class again.

The use of static code blocks and static lights of a class does not depend on the loading of the class. That is, using a static variable of a class does not trigger the loading of that class.

/**
 * Created by gongxufan on 3/31/16.
 */
 class Parent{
 public static final String const_str = "Super";
 static{
 System.out.println("Super Class Init");
 bracket
 public Parent(){
 System.out.println("Super Class Init");
 bracket
 bracket
 
 class Child extends Parent{
 public static final String const_str_child = "Super";
 static {
 System.out.println("Child Class Init");
 System.out.println(const_str);
 bracket
 bracket
 public class SuperClassInit {
 public static void main(String[] args) {
 System.out.println(Child.const_str);
 bracket
 bracket