Geez, I hope that wasn't one of my questions... was it?
In any case, on the real exam (and mock exam creators SHOULD follow this rule although they probably don't):
- when a code listing starts at line 1, assume you're seeing the entire file
- if there are multiple files, the question will either say that, or each file will start at line 1.
So the mock question you showed, if you copied it exactly correctly, doesn't follow standards - the second program should restart at line 1.
Exactly as described would've been no numbers. The text editor automatically put those in when I used code tags. Exactly would've been the same with the following line,
Given two files:
package xcom;
public class Stuff{
static int MY_CONSTANT = 5;
static int doStuff(int x) { return (x++)*5; }
}
import static xcom.Stuff.*;
import static java.lang.System.out;
class User {
public static void main(
String[] args) {
new User().go();
}
void go() { out.println(doStuff(MY_CONSTANT));}
I'm not using code tags now to avoid confusion.
Also the following questions were on the quiz in the CD from your book:
Given:
What's the output?
The given correct answer is:
Created a Father Well, that's all right then.
Wrong.
It would show as two lines give that println was used both times.
And a more substantial example:
Given:
Which of the following will fulfill the equals() and hashCode() contracts for this class? (Choose all the apply)
return ((SortOf)o).code.length()*((SortOf)o).bal*((SortOf)o).rate== this.code.length()*this.bal*this.rate;
is given as a correct answer.
It's not and the reason given is even worse: Te equals() algorithm must be at least as precise in defining what "meaningfully equivalent" means as the hashCode() method is.
?
One of the basic rules of equals() and hashCode() is that if two objects return true on equals() they
must have the same hash code.
Here's a trivially easy example of this problem.
foo.code = "yes";
foo.bal = 2;
foo.rate = 2;
bar.code = "not";
bar.bal = 1;
bar.rate = 4;
Both equals products ==12 so they are "equal" but their hash values are 6 and 3, so, they won't be in the same hash bucket, and they will never be found on a search.