Topic: 几道问题 有待解决 如能帮忙 不胜感激

  Print this page

1.几道问题 有待解决 如能帮忙 不胜感激 Copy to clipboard
Posted by: xujunfbi
Posted on: 2004-08-05 11:39

QUESTION NO: 49
Given:
10. public Object m() {
11. Object o = new Float(3.14F);
12. Object [] oa = new Object[1];
13. oa[0] = o;
14. o = null;
15. oa[0] = null;
16. return 0;
17. }
When is the Float object, created in line 11, eligible for garbage collection?
A. Just after line 13.
B. Just after line 14.
C. Just after line 15.
D. Just after line 16 (that is, as the method returns).

--------------------------------------------------------------------------------

1. public class Test {
2. public static void main(String[] args) {
3. int x = 0;
4. assert (x > 0): “assertion failed”;
5. System.out.println(“finished”);
6. }
7. }
What is the result?
A. finished
B. Compilation fails.
C. An AssertionError is thrown.
D. An AssertionError is thrown and finished is output.

------------------------------------------------------------------------------------------------

Which two statements are true regarding the return values of property written
hashCode and equals methods from two instances of the same class? (Choose two)
A. If the hashCode values are different, the objects might be equal.
B. If the hashCode values are the same, the object must be equal.
C. If the hashCode values are the same, the objects might be equal.
D. If the hashCode values are different, the objects must be unequal.

2.Re:几道问题 有待解决 如能帮忙 不胜感激 [Re: xujunfbi] Copy to clipboard
Posted by: looluo
Posted on: 2004-08-05 17:00

1.C 2.A 3.CD

3.Re:几道问题 有待解决 如能帮忙 不胜感激 [Re: xujunfbi] Copy to clipboard
Posted by: kempguan
Posted on: 2004-08-06 15:34

2.C

4.Re:几道问题 有待解决 如能帮忙 不胜感激 [Re: xujunfbi] Copy to clipboard
Posted by: czgdjzy
Posted on: 2004-08-06 17:21

c.If the hashCode values are the same, the objects might be equal.

举个例子或说明一下hashcode谢谢!

5.Re:几道问题 有待解决 如能帮忙 不胜感激 [Re: xujunfbi] Copy to clipboard
Posted by: bsspirit
Posted on: 2004-08-08 23:35

我也想知道第三题!!!!

第二题选:B

assert是断言的意思, 只能在命令行启动是才可以用.

这个程序没有提示在命令行启动,因此程序不认识,这个关键字.Compilation fails.

6.Re:几道问题 有待解决 如能帮忙 不胜感激 [Re: xujunfbi] Copy to clipboard
Posted by: vk2001
Posted on: 2004-08-09 18:04

A hashCode()that returns the same value for all instances whether they’re
equal or not is still a legal—even appropriate— hashCode()method!
For example:
=====================
public int hashCode() {
return 1492;
}
=========================
would not violate the contract. Two objects with an x value of 8 will have
the same hashcode. But then again, so will two unequal objects, one
with an x value of 12 and the other a value of -920.
so,If the hashCode values are the same, the objects "might" be equal,not "must".

7.Re:几道问题 有待解决 如能帮忙 不胜感激 [Re: xujunfbi] Copy to clipboard
Posted by: vk2001
Posted on: 2004-08-09 18:10

remember these two rules:
1.If two objects are equal, their hashcodes must be equal .
2.If two objects's hashcodes are equal,the objects can not be equal!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923