File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface question from JQPlus

 
Jay Ashar
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sekhar Kadiyala
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

JLS chapter "12.4 Initialization of Classes and Interfaces"

Is it a book or online tutorial?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sekhar Kadiyala
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Corey, Thank you.
 
Jay Ashar
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic