I don't understand why it is not printing out the vakues for i and k from the out method???
Lakshmi as per your quote,
I think,in interface the variables must be initialized at thier declaration.But here the code is containing method calls
I also have the same doubt as in interface all variables are implicitly public static final. So in the above code, the call ii = Main.out("ii", 2) assigns ii the vakue of 2 only after the method returns the value. So why does this not produce any compile time errors??
Obviously, the fields of ancestors of an interface are only initialized when the corresponding interface they are declared in is accessed first (and not, how it would be expected for classes, when the child interface is loaded).
To make it clearer: when a static field of a class is first accessed, all ancestor classes are loaded recursively, including the initialization of the respective static fields.
On the other hand, when a (always static) field of an interface is first accessed, the fields of it's ancestors are not initialized. Only it's own fields are initialized.
The reference to J.i is to a field that is a compile-time constant; therefore, it does not cause I to be initialized. The reference to K.j is a reference to a field actually declared in interface J that is not a compile-time constant; this causes initialization of the fields of interface J, but not those of its superinterface I, nor those of interface K. Despite the fact that the name K is used to refer to field j of interface J, interface K is not initialized.