• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

4m Dan's Exam

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code is from Dan's Exam :


Pls. clear it.

Mohit Agarwal.
Would be SCJP.
"The will to win is worthless if u do not have the will to prepare"
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to analyze it keeping in mind that an interface's constants are only initialized when they are actually needed.

v is certainly needed because it is printed, but are E.w, F.x, F.y and F.z?
[ October 04, 2004: Message edited by: Barry Gaunt ]
 
Mohit Agarwal
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Bary that's what i find out when i experimented with the code,
but really i don't know that "an interface's constants are only initialized when they are actually needed. "
But they are implicitly final vars which are to be initialized befor the constructor completes .

I had read this. I am using kathy and Bert.

Pls. clear it more.


Mohit Agarwal.
Would be SCJP.
"The will to win is worthless if u do not have the will to prepare"
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try the following code out:

 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tom,

I have tried your code and it runs without any problem but my question is " why it doesn't print 'w'?".

I know it is in the parent interface of E, but when child interface is executed then why not Parent interface.


Kaps
 
Mohit Agarwal
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry Tom i didn't get your point.
Moreover my Q remains unanswered.
Pls. let me know about that.


Mohit Agarwal.
Would be SCJP.
"The will to win is worthless if u do not have the will to prepare"
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer to your question lies in this section of JLS

What Tom's example points out is that when an interface is initialized (because one of the members in used) then all of the members of the interface are initialized in texual order.

And that superinterfaces are not necessarily initialized when extension interfaces are.
[ October 05, 2004: Message edited by: Barry Gaunt ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic