Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null reference/JQuest question

 
Weigang Gu
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, folks, here is a question from JQuest:
public class TestNull {
public void method(Object o) {
System.out.println("Object Version");
}
public void method(String s) {
System.out.println("String Version");
}
public static void main(String args[]) {
Test test = new Test();
test.method(null);
}
}
The answer gives "String version". However, when i compile, it says method(null) can not be found in test.
what do you think?
 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your main method should be:
public static void main(String args[]) {
TestNull test = new TestNull();
test.method(null);
}
The reason for "it says method(null) can not be found in test"
is that you probably have another class called Test in your working directory.
I don't know why the answer is "String version" though, maybe someone else knows?

[This message has been edited by greg philpott (edited January 30, 2001).]
 
Weigang Gu
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right.
thanks
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ...
Here is a link earlier discussion on the same question that might help.

------------------
Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic