Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

4m Dan's Exam

 
Mohit Agarwal
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • 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"
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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
  • 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"
 
Tom Tolman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the following code out:

 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic