aspose file tools*
The moose likes Mock Exam Errata and the fly likes Java Rules Round #154 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Java Rules Round #154" Watch "Java Rules Round #154" New topic
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: 810
just tell me that
whether
;
statement in java program will not cause compiler error ?
just asking...



Thanks and Regards, Amit Taneja
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
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(){;;};;;;;;;;;;;;;;;;;;;;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Rules Round #154