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