|
"if x5.equals(x6) == true, which of the following statements will always be true?"
Correct answer:
C: x5.hashCode() == x6.hashCode();
Explanation: By contract, if .....
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
If two objects are equal according to the equals(Object) method, then calling
the hashCode method on each of the two objects must produce the same
integer result.
"Eppur si muove!"
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
IS-A relationships always require at least two class types, and always rely on polymorphism
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Gian Franco wrote:Have a look a the contract
It saysIf two objects are equal according to the equals(Object) method, then calling
the hashCode method on each of the two objects must produce the same
integer result.
which is one of the rules one has to comply with in order to write a correct equals() method.
Therefore if two objects return different hashCodes they cannot be equal.
Of course the default equals() and hashCode() fullfil all these rules.
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Dieter Quickfend wrote:
So, "Integer IS-A Integer" is not a correct statement?
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Dieter Quickfend wrote:I can't give the full question, because it's in the exam engine and I can't copy it, but basically, to summarize:
"if x5.equals(x6) == true, which of the following statements will always be true?"
Correct answer:
C: x5.hashCode() == x6.hashCode();
Explanation: By contract, if .....
...What did I miss? By contract? That wasn't in the question...
Cheers,
Divyesh.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Regards,
Avishkar Nikale
Cheers,
Divyesh.
SCJP6.0,My blog Ranchers from Delhi
Cheers,
Divyesh.
Divyeshh Patel wrote:This question is from Apress book for SCJP, chapter 8, Question 6
Consider the following code:
1. FileOutputStream out=new FileOutputStream("objectStore.ser");
2. ObjectOutputStream os = new ObjectOutputStream(out);
3. os.writeObject("Object on the fly!");
What is the result of this code?
A. The string "Object on the fly!" is written into the file objectStore.ser.
B. Line 3 causes a compiler error.
C. The code compiles fine but an exception is thrown at line 3 when the code is executed.
D. An exception occurs at line 2.
E. A compiler error occurs at line 2.
I assumed that the answer would be compiler error at line 1 which does not appear in the option list, but they wanted me to assume that the code is enclosed in try-catch...
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar wrote:It could also be compiler error because they donot give the assumption for import statement...
and code given by you requires following
statement........
Cheers,
Divyesh.
Bert Bates wrote:Hi Dieter,
Just FYI, it's fine to take a screenshot of a mock question and post the screenshot here, as long as you mention where the question came from.
hth,
Bert
Abimaran Kugathasan wrote:
Dieter Quickfend wrote:
So, "Integer IS-A Integer" is not a correct statement?
Obvious!
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
"Eppur si muove!"
Your mind is under my control .... your will is now mine .... read this tiny ad
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|