Here are the questions the answers to which baffled me based on what I learnt from other books plus the wording of the answers.
This from the JExam mock exam.
Here are the questions. (Ignore HTML Tags)
What is the output from the following piece of code:
loop1:
for(int i = 0; i < 3; i++){
loop2:
for(int j = 0; j < 3; j++){
if (i == j){
break loop2;
}
System.out.print("i = " + i + " j = " + j + " ");
}
}
There are several answers :-
1. Some number output
2. Some number output
3. Some number output
4. None of the above.
According to Bill Brogdens book, Java Cram, he says that a label cannot stand by itself, it has to be part of a statement, This turns out to be wrong. I successfully compiled and ran the above example.
Any comments ?
Q.2
Before which of the following can the keyword "synchronized" be placed, without causing a compile error.
Choices:
1. class methods
2. instance methods
3. variables
4. classes
My Choice ... 1,2,3 .... but the exam says choice 3 is not correct
I compiled and ran it works. Although choice 3 is not a sensible thing, but question says will it compile or not... it does.
Any comments.
Q.3. I dont have the exact one, but this is how it goes.
How many components can you add to a sector of a BorderLayout Container
Answer:
1.One
2.Any number of Components
3.Some other choice
The answer was: You can add only one Component to any sector, if you want to add more than one, then add the components to another container such as Panel and then add the panel to the sector.
This is the correct explaination, but the question is not how many components are displayed in a sector, the question is how many you can add. I can add as many as I want ( cant I) but only one will be displayed. example the CENTER.
I can go on adding, only the last one will be visible, but complier allows me to add.
Please advise, if I am wrong in reading the question correctly or its close to Friday and everthing is not fair in love and war.
Thanks in advance.