OCAJP SE 7 - Question - Fulfills the contract?
Posted: Sat Jun 08, 2013 11:43 pm
I am preparing for OCAJP SE 7 and have a question. I have read several books and am using the Enthuware Mock Exams (which are great!) but haven't seen this phrase used yet. Any help is much appreciated!
What does it mean to 'fulfill the Object.equals() contract.'?
Below, please find a sample question using this phrase provided on Oracle's website at
http://education.oracle.com/pls/web_pro ... =SQ1Z0_803
The answer is 'C'
2. Given:
The answer is 'C'
What is the result?
A) The output is "true" and MyStuff fulfills the Object.equals() contract.
B) The output is "false" and MyStuff fulfills the Object.equals() contract.
C) The output is "true" and MyStuff does NOT fulfill the Object.equals() contract.
D) The output is "false" and MyStuff does NOT fulfill the Object.equals() contract
E) Compilation fails
What does it mean to 'fulfill the Object.equals() contract.'?
Below, please find a sample question using this phrase provided on Oracle's website at
http://education.oracle.com/pls/web_pro ... =SQ1Z0_803
The answer is 'C'
2. Given:
Code: Select all
public class MyStuff {
MyStuff(String n) { name = n; }
String name;
public static void main(String[] args) {
MyStuff m1 = new MyStuff("guitar");
MyStuff m2 = new MyStuff("tv");
System.out.println(m2.equals(m1));
}
public boolean equals(Object o) {
MyStuff m = (MyStuff) o;
if(m.name != null)
return true;
return false;
}
}
What is the result?
A) The output is "true" and MyStuff fulfills the Object.equals() contract.
B) The output is "false" and MyStuff fulfills the Object.equals() contract.
C) The output is "true" and MyStuff does NOT fulfill the Object.equals() contract.
D) The output is "false" and MyStuff does NOT fulfill the Object.equals() contract
E) Compilation fails