Escolar Documentos
Profissional Documentos
Cultura Documentos
import java.util.Date;
method(d1, d2);
System.out.println("d1 is " + d1
d2.setYear (100);
d1 = d2;
Which one or more of the following correctly describe the behavior when this
program is compiled and run?
d) the assignment 'd1 = d2' is rejected by the compiler because the Date class cannot overload
the operator '='.
e) the expression (d1 is " + d1 + "\nd2 is " + d2) is rejected by the compiler because the Date
class cannot overload the operator '+'.
Correct Answer: B
Explanation:
d) is false as code is perfectly legal, Object d1 is set to be the same as d2. This is a change of the
actual reference, not in the data at d1.
e) is false, because Java is smart enough to call the method toString() for any object that is used in
a String context. toString() is defined by the Object class and so it is available on all classes in Java.
Most non-trivial classes override toString() to return more explicit information about themselves.
}
1. public class Test2 extends Test1{
2.
3. }
A is illegal because it is less accessible than the original method, because method in
Test1 is public. And for any overriding method, accessibility must not be more
restricted than the original method.
C is illegal because for overriding method, it must not throw checked exception of
classess that are not possible for the origincal classes.
Q8. A monitor called mon has 5 threads in its waiting pool; all these waiting threads have the same
priority. One of the threads is thread1. How can you notify thread1 so that it alone moves from
Waiting state to Ready State?
Explanation:
E is correct, when you call notify() on a monitor, you have no control over which waiting thread gets notified.
Q9. What happens when the following code is compiled and run. Select the one correct
answer.
Explanation:
correct answer is B. When i and j are both 1, assert condition is false, and AssertionError gets generated.