• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Interface question from JQPlus

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,


JLS chapter "12.4 Initialization of Classes and Interfaces"


Is it a book or online tutorial?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey, Thank you.
 
Jay Ashar
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Well THAT's new! Comfort me, reliable tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic