File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in if() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in if()" Watch "Doubt in if()" New topic
Author

Doubt in if()

Uttara Rishi
Ranch Hand

Joined: Feb 24, 2008
Posts: 49
Hi Ranchers,

Please have a look at the following code....




Output is : Sample

My doubt is why are we not getting a complier error on Line 1 (because of the semicolon)?

Thanks in advance.

Uttara Rishi.
sandhi mridul
Ranch Hand

Joined: Jan 25, 2008
Posts: 71
As semicolon is there after if statement it does not have any effect on the program. It will remain as it is in the program and also will not not give any compiling and runtime error.
Because the if statement get terminated due to semicolon.

[ February 29, 2008: Message edited by: sandhi mridul ]
[ February 29, 2008: Message edited by: sandhi mridul ]
Subhankar Kushary
Greenhorn

Joined: Feb 24, 2008
Posts: 4
The is just a blank if statement which does nothing.
So when is called it calls the test method, does nothing [if(false);] and then sample() method outputs the "Sample".
Here sample() method is not conditional,it executes always irrespective of the flag.
Uttara Rishi
Ranch Hand

Joined: Feb 24, 2008
Posts: 49
Thanks guys that helped.
 
 
subject: Doubt in if()