Question 70 on Applied Reasoning Mock:
<pre>
what is the result of compiling and executing the following program?
public class StaticTest2{
1: public static void main(
String[] args) {
2:me().run();
3:}
4 : public static StaticTest2 me() {
5:System.out.print("Me");
6:return null;
7:}
8 : public static void run(){
9:System.out.println("Run");
10:}
}
</pre>
answer: MeRun will be printed to the system console
This proves to be right; I just need a quick check on the reasoning here because the
applet wasn't clear. The run() method is called on whatever object is returned from me(), which is declared in the me() signature as a StaticTest2 object return type. But the method actually returns null. So, I assume (since I thought it would throw NullPointerException) that since everything is bound at compile time, it just assumes you're going to get a StaticTest2 object and reacts as if you do. Could that possibly be right? Doesn't the null wreak havoc somewhere or does it get off clean
?
Thanks a lot
Eric
[This message has been edited by Eric Barnhill (edited May 10, 2000).]