File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface question from JQPlus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface question from JQPlus" Watch "Interface question from JQPlus" New topic
Author

Interface question from JQPlus

Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208

What will be the output when class Test is run ?
Answer is
It will print j = 3, jj=4 and then 3.
Does anyone know why is it printing jj=4 too??
Edited by Corey McGlone: Added CODE Tags
[ March 08, 2004: Message edited by: Corey McGlone ]

SCJP 1.4<br />SCWCD 1.3
Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
Hi Jay,
Check out the JLS chapter "12.4 Initialization of Classes and Interfaces".
I will do that myself as well. It explains your problem.
Best regards,
Gian Franco Casula
[ March 08, 2004: Message edited by: Gian Franco Casula ]

"Eppur si muove!"
Sekhar Kadiyala
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
Hi Guys,

JLS chapter "12.4 Initialization of Classes and Interfaces"

Is it a book or online tutorial?


PMP CSQA SCJP SCWCD SCBCD INS 21 INS 23
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Sekhar Kadiyala:
Hi Guys,

Is it a book or online tutorial?

The JLS stands for Java Language Specification and is the ultimate source for all Java related questions (at least concerning the exam). You can find the entire specification online here.


SCJP Tipline, etc.
Sekhar Kadiyala
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
Corey, Thank you.
Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208
I found the answer
"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."
Thanks Corey and Gian
[ March 08, 2004: Message edited by: Jay Patel ]
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
I'm glad you found it, Jay. I was hoping you'd take the initiative to hunt through the JLS for the answer - get used to using the JLS. The SCJP exam is based on it so, if you can find your way around it, you're much better off.
 
jQuery in Action, 2nd edition
 
subject: Interface question from JQPlus