• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Que on JohnHunt exam

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How is line #1 is executed. The value for Test4.this.flag would be false .
Am i right? or am i missing something out here...
-Sanjana
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sanjana, note the semi-colon at the end of the if-stat.

That is why sample() is executed regardlass the if-stat.
Hope this helps.
[ January 04, 2004: Message edited by: Vicken Karaoghlanian ]
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Btw shouldn't class Test4 be declared static so you can call it directly like is mentionned ??
if (Test4.this.flag); {//1
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kristof,
Great question! I was stumped on that myself.
The answer can be found in the JLS at15.8.4
It's a 'qualified this' reference. An enclosed class can refer to members of it's enclosing class via <Enclosing Class Name>.this.<member>
Interestingly enough, the depth of the inner class doesn't seem to matter:

o/p:
I : false
II : true
II : false

Thank You
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic