aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Initialization Related Prob Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Initialization Related Prob" Watch "Initialization Related Prob" New topic
Author

Initialization Related Prob

Shalini Banerjee
Greenhorn

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,
j=3
jj=4
3


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
Greenhorn

Joined: Dec 06, 2005
Posts: 22
Ok...thnx for your suggesion.
But still i want the explanation from somebody who can explain it.
Chandrakanth
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
http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Initialization Related Prob
 
Similar Threads
Initialization of Interfaces
Interface Doubt
Interface question
Question from Enthuware
Interface Q