Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

John Hunt Question 62

 
Melissa Ting
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there...
I have a silly questions. Please be patient with me. I don't understand why it will print Sample becuase I thought that the flag = false. Since it's false how come it will execute sample.
Thanks in advance.

Q. 62
Examine the following code which includes an inner class:

public final class Test4 implements A {
class Inner {
void test() {
if (Test4.this.flag); {
sample();
}
}
}
private boolean flag = false;
public void sample() {
System.out.println("Sample");
}
public Test4() {
(new Inner()).test();
}
public static void main(String args []) {
new Test4();
}
}

What is the result:
A. Prints out "Sample"
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
 
Paul Villangca
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Notice the semicolon (;) just after your if statement. That should make everything clear.
Heh, silly me, there's a smiley in my post.
[ June 19, 2002: Message edited by: Paul Villangca ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic