Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Que on JohnHunt exam

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic