Question 24
11. class Snoochy {
12. Boochybooch;
13. public Snoochy() { booch = new Boochy(this); }
14. }
15.
16. class Boochy {
17. Snoochy snooch;
18. public Boochy(Snoochy s) { snooch = s; }
19. }
And the statements:
21. public static void main(String[] args) {
22. Snoochy snoog = new Snoochy();
23. snoog = null;
24. // more code here
Copyright Tarena Corporation,2008.All rights reserved
25. }
Which statement is true about the objects referenced by snoog,
snooch, and booch immediately after line 23 executes?
A. None of these objects are eligible for garbage collection.
B. Only the object referenced by booch is eligible for garbage
collection.
C. Only the object referenced by snoog is eligible for garbage
collection.
D. Only the object referenced by snooch is eligible for garbage
collection.
E. The objects referenced by snooch and booch are eligible for garbage
collection.
Answer: EQuestion 30
Given:
11. public class Commander {
12. public static void main(String[] args) {
13. String myProp = /* insert code here */
14. System.out.println(myProp);
15. }
16. }
and the command line:
java -Dprop.custom=gobstopper Commander
Which two, placed on line 13, will produce the output gobstopper?
(Choose two.)
A. System.load("prop.custom");
B. System.getenv("prop.custom");
C. System.property("prop.custom");
D. System.getProperty("prop.custom");
E. System.getProperties().getProperty("prop.custom");
Answer: DEQuestion 35
A UNIX user named Bob wants to replace his chess program with a
new one, but he is hot sure where the old one is installed. Bob is
currently able to run a Java chess program starting from his home
directory /home/bob using the command:
java -classpath /test:/home/bob/downloads/* .jar games.Chess
Bob’s CLASSPATH is set (at login time) to:
/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/* .jar
What is a possible location for the Chess.class file?
A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)
G. inside jarfile /home/bob/downloads/Games.jar (with a correct
manifest)
Answer: C小弟快考scjp了,有些题还没弄懂,请高手指教,答案已给,求解释

解决方案 »

  1.   

    第一题:画个图就知道了。snooch = null这后,snooch和booch都是指向了null,都可以被garbage collected.
    第二题:-Dprop是用来设置系统变量的,所以要用System.getProperty方法。System.load是用来载入动态库的,System.getenv方法没有参数
    第三题:考的是-classpath的用法。javaAPI中有一句话:Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable. 也就是说如用在运行程序时用了-classpath,原来系统载入的CLASSPATH就被覆盖了,所以B,D,E,F.而且运行是又指明了包明,所以A是不的。C是对的,G也应该是对的。不明白为什么答案只有C?