Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "else if" one whole or two separate keywords in Java?

Tags:

java

I happen to read the practicing material for SCJP certification, and I just tripped over a chapter of flow control et al, where they give the impression that "else if" is a keyword on its own. I have always thought that it was just a normal else, containing nothing but an if block, braces omitted.

So, which is it?

Edit: I'd like to emphasize that this question is more in the "pique my interest" category than the "serious business" one.

like image 863
Henrik Paul Avatar asked Apr 19 '09 22:04

Henrik Paul


2 Answers

Yes, they are two separate keywords—the Java language specification does not specify an else if keyword. It is actually, as the other posters here have said, an if statement contained inside of an else statement.

EDIT: A lot of training/educational materials seem to imply that else if is actually a keyword (and, indeed, it is usually treated as such), but I am inclined to think that this is more for the sake of clarity/simplicity, with the consequence of sacrificing accuracy.

like image 89
hbw Avatar answered Sep 28 '22 08:09

hbw


it would be two separate keywords indicated by the space between the two words.

like image 37
zpesk Avatar answered Sep 28 '22 06:09

zpesk