Women in Technology

Hear us Roar



Article:
  Understanding the Interplay Between Utility Classes and Static Initialization
Subject:   Diversion: explanation for "skipped" subclass initializer
Date:   2004-09-21 11:29:56
From:   cfelaco
The thing to remember is that all static code is resolved staticly - in other words, at compile time. When you reference SubClass.staticVar in your program, the Java Compiler searches for "staticVar" in the definition of SubClass first, and then failing that, it searches its ancestors. Ultimately the compiler will generate code to initialize only the class that the static method or field came from. This is why good compilers (like the one in Eclipse) now warn programmers about accesses to static members through anything other than the class that owns the member.