aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes questions from khalid's mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "questions from khalid Watch "questions from khalid New topic
Author

questions from khalid's mock exam

vasu matt
Greenhorn

Joined: Dec 21, 2000
Posts: 15
can anybody please explain me the answers for this queries,i do not know the answer actually.these are from khalids mock papersWhich is the earliest line in the following code after which the object created on the line marked (0) will be a candidate for being garbage collected, assuming no compiler optimizations are done?
code/
1)
public class Q76a9 {
static String f() {
String a = "hello";
String b = "bye"; // (0)
String c = b + "!"; // (1)
String d = b;
b = a; // (2)
d = a; // (3)
return c; // (4)
}
public static void main(String args[]) {
String msg = f();
System.out.println(msg); // (5)
}
}
1)the line marked(1)
2)the line marked (2)
3)the line marked (3)
4)the line marked (4)
5)the line marked (5)
2)
Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work?
CODE BLOCK A:
Runnable r = new Runnable() {
public void run() {
Work.doIt();
}
};
Thread t = new Thread(r);
t.start();
CODE BLOCK B:
Thread t = new Thread() {
public void start() {
Work.doIt();
}
};
t.start();
CODE BLOCK C:
Runnable r = new Runnable() {
public void run() {
Work.doIt();
}
};
r.start();
CODE BLOCK D:
Thread t = new Thread(new Work());
t.start();
CODE BLOCK E:
Runnable t = new Runnable() {
public void run() {
Work.doIt();
}
};
t.run();
1)code block A
2)code block B
3)code block C
4)code block D
5)code block E
/code
Jenny Xia
Greenhorn

Joined: Dec 22, 2000
Posts: 2
For Q1, the answer is 3).
the program created three String objects: "hello", "bye" and "bye!" when the main() method executed.
The reference varibles reference to objects in following sequence:
hello 1.a 5.b 6.d
bye 2.b 4.d 5.(b not reference bye any more) 6.(d not reference bye any more)
bye! 3.c
Since bye has no reference variable reference to it, it is ready for gc to collect it at line(3) in your code.
About Q2 you can see explation by Bill Bozeman's post.

[This message has been edited by Jenny Xia (edited December 22, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: questions from khalid's mock exam