It compiles fine, now instead of "this.i" i replace with i, and instead of Initializers1.k i have k, It gives compiler errors in the lines. This code would give compiler errors:
Please let me know any suitable explanation for such behaviour Thanks
posted 11 years ago
static members are resolved (and thus initialised) in the order they are declared. As you're declaring k only after its first use in the initialisation of z you're getting an error. In the first case you're getting a forward reference which is resolved at runtime, in the second it's (attempted to be) resolved at compile time.