| Author |
Java Rules Round #154
|
Win jones
Ranch Hand
Joined: Dec 12, 2004
Posts: 38
|
|
Question ) Assuming all variables are declared and initialized properly will the following code compile for (i = 1; k <5;j++){}; why is there a semi-colon after the last curly brace because of that the code will not compile
|
 |
Mukesh Poddar
Greenhorn
Joined: Jan 14, 2005
Posts: 8
|
|
As your Question itself says ...all the variables i,j,k are declared and initialized properly..... The program will run Succesfully..... Since in Java an ; separates the One statement from the other...... And the Bracket before the "{}" dosen't signify anything it just gives compiler the infiormation that a new block is started.... so te compiler will treate as a null statement.... and compile the program succesfully.....
|
 |
amit taneja
Ranch Hand
Joined: Mar 14, 2003
Posts: 806
|
|
just tell me that whether ; statement in java program will not cause compiler error ? just asking...
|
Thanks and Regards,<br />Amit Taneja
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
Originally posted by amit taneja: just tell me that whether ; statement in java program will not cause compiler error ?
An extra semicolon after the curly brace will not cause a compiler error.
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Rick O'Shay
Ranch Hand
Joined: Sep 19, 2004
Posts: 531
|
|
Originally posted by amit taneja: just tell me that whether ; statement in java program will not cause compiler error ? just asking...
The semicolon designates an empty statement: // OK class Foo { void bar() {} int x; } // OK class Foo { void bar() {} ; } // OK class Foo { void bar() {}; } // OK class Foo { ;;;;;;;;;;;void bar(){;;};;;;;;;;;;;;;;;;;;;; }
|
 |
 |
|
|
subject: Java Rules Round #154
|
|
|