当前位置: 技术问答>java相关
谁是高手谁来看看这两道题怎么回事情
来源: 互联网 发布时间:2015-02-15
本文导语: 36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A? String name; String newName = "Nick"; newName = "Jason"; name = "Frieda"; String newestName = name; name = null; //Line A a)...
36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A?
String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A
a) 0
b) 1
c) 2
d) 3
e) 4
37. Which of the following statements about Java's garbage collection are true?
a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.
36题的答案是b,37题的答案是abc
敢问各位大哥这两道题是不是答案错了?
String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A
a) 0
b) 1
c) 2
d) 3
e) 4
37. Which of the following statements about Java's garbage collection are true?
a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.
36题的答案是b,37题的答案是abc
敢问各位大哥这两道题是不是答案错了?
|
小衲认为答案是对的
36中,只有"Nick"这个String没有reference,可能被GCed
37a:
java.lang.System.gc() (等效于) Runtime.getRuntime().gc()
可以用来“请求”JVM进行GC,但不一定马上有效。。。
37c:所有的类都是java.lang.Object的子类,如果你在
你的类中override了Object的finalize() 方法,则在最后一行,
应该/必须加上:
super.finalize();
有几本书上讨论过这个问题,可能Thinking in Java上有。。。
也可以在www.google.com上用finalize() Java来搜索。。。
36中,只有"Nick"这个String没有reference,可能被GCed
37a:
java.lang.System.gc() (等效于) Runtime.getRuntime().gc()
可以用来“请求”JVM进行GC,但不一定马上有效。。。
37c:所有的类都是java.lang.Object的子类,如果你在
你的类中override了Object的finalize() 方法,则在最后一行,
应该/必须加上:
super.finalize();
有几本书上讨论过这个问题,可能Thinking in Java上有。。。
也可以在www.google.com上用finalize() Java来搜索。。。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。