• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applied Reasoning Mock #70

 
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
eric,
I tried this program. This one also works fine!!
public class StaticTest2
{
public static void main(String[] args)
{
StaticTest2 s = null;
s.run();
}
public static void run()
{
System.out.println("Run");
}
}
The result is
Run
So, I think the type is bound at runtime itself!!
Hope it helps!!
Regards,
Suresh.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suresh,
I guess you meant to say at Compile time ??

Ajith
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic