aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ; after the if statement 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 "; after the if statement" Watch "; after the if statement" New topic
Author

; after the if statement

santhy sugathan
Greenhorn

Joined: Dec 13, 2000
Posts: 4
Hi,
I am new to this forum and got a question. I saw this question in the JDcert mock exam and got a doubt.
In this code, what will be the output? I tried tu run and got "Sample" as the output. But why the compiler passes this statement "if (Test4.this.flag); ", ie, if ending with a semicolon?
public final class Test4 {
class Inner {
void test() {
if (Test4.this.flag); {
sample();
}
}
}
private boolean flag = true;
public void sample() {
System.out.println("Sample");
}
public Test4() {
(new Inner()).test();
}
public static void main(String args []) {
new Test4();
}
}

Somebody pls help me.
Thanks
Santhy
Nasir Khan
Ranch Hand

Joined: Nov 04, 2000
Posts: 135
Hi santhy,
Answer to your question is here http://www.javaranch.com/ubb/Forum24/HTML/006278.html
Sam Wong
Ranch Hand

Joined: Dec 07, 2000
Posts: 133
if (Test4.this.flag);
{
sample();
}
The if statement states that if flag is true, do nothing. The semicolon alone is same as an empty statement. The rest is an instance initialization block. Hope this helps.
santhy sugathan
Greenhorn

Joined: Dec 13, 2000
Posts: 4
Thanks Nasir and Sam. Really apperciate it.
Santhy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ; after the if statement