aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Please Explain Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Please Explain" Watch "Please Explain" New topic
Author

Please Explain

vinay jain
Greenhorn

Joined: Nov 07, 2001
Posts: 27
<pre>
public final class Test4 {
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();
}
}
</pre>
In the above code the answer is printed "Sample" on the standard output. Can anyone please explain why?
vinay jain
Greenhorn

Joined: Nov 07, 2001
Posts: 27
More Info on the mentioned Question. It is from John Hunt's Mock Exam, Question 62?
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 128
It's a trick question. Notice the ";" after the "if" statement. In this case, there is no action taken as a result of the "if" determination. The program then will simply go to the next line of code: sample().
While this type of question is fair game in the SCJP exam. I didn't have any of these types of trick questions.


Darryl Failla
Sun Certified Java 2 Programmer
vinay jain
Greenhorn

Joined: Nov 07, 2001
Posts: 27
Thanks Darryl
I was confused about 2 things and I noticed the ; after your answer and 1 thing got cleared. The other thing that I was confused about was the use of <OuterClassName>.this.<outerClassMember> but then I read a little bit about it too and cleared that too. Thanks for the timely response and making things clear for me.
Vinay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Explain