Originally posted by Zahid, Butt:
Hi ALL,
By the way, the question was from JQ+, under the
"Easy Questions" section of mock exams.
Thanks.
...the following statement results in a compile-time error:
while (false) { x=3; }
because the statement x=3; is not reachable; but the superficially similar case:
if (false) { x=3; }
does not result in a compile-time error. An optimizing compiler may realize that the statement x=3; will never be executed and may choose to omit the code for that statement from the generated class file, but the statement x=3; is not regarded as "unreachable" in the technical sense specified here.
The rationale for this differing treatment is to allow programmers to define "flag variables" such as:
static final boolean DEBUG = false;
and then write code such as:
if (DEBUG) { x=3; }
The idea is that it should be possible to change the value of DEBUG from false to true or from true to false and then compile the code correctly with no other changes to the program text.
I have read in order to declare an abstract class you must have at least one abstract method is this true?
Not true, its the other way around. If you declare an abstract method in a class, then that class must be declared abstract. An abstract class may have non-abstract methods.
Also , is null a keyord? I was taking a mock exam and it said it was not.
null, just like true and false is a reserved literal, not a keyword.
I understand bitwise operators, but I do not understand why this returns 12 instead of 14 System.out.println(010|4);
10 equals 1010
4 equals 0100
result 1110 = 14
can anybody please explain it in plain english, maybe toss in an example?
010 is octal representation of decimal 8 or binary 001 000. Therefore, 1000 | 0100 == 1100 (decimal 12).