wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Initialization Related Prob Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Initialization Related Prob" Watch "Initialization Related Prob" New topic

Initialization Related Prob

Shalini Banerjee

Joined: Dec 06, 2005
Posts: 22
interface I
int i = 1, ii = Test.out("ii", 2);
interface J extends I
int j = Test.out("j", 3), jj = Test.out("jj", 4);
interface K extends J
int k = Test.out("k", 5);
class Test
public static void main(String[] args) { System.out.println(K.j); }
public static int out(String s, int i)
System.out.println(s + "=" + i);
return i;

why the answer is,

please explain.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
hi shalini,

you wont get such exams in the exam. this question has been posted previously on javaranch.

the exma tests you on how better you understand the objectives and not on the runtime and compile time behaviour of a code containinig interfaces

so ignore this code

SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Shalini Banerjee

Joined: Dec 06, 2005
Posts: 22
Ok...thnx for your suggesion.
But still i want the explanation from somebody who can explain it.
Ranch Hand

Joined: Aug 16, 2005
Posts: 60
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.

you can refer to this link to know more on this:JLS
It is sorta covered in the JavaRanch Style Guide.
subject: Initialization Related Prob
Similar Threads
Interface Q
Question from Enthuware
Initialization of Interfaces
Interface question
Interface Doubt