*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes null reference/JQuest question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "null reference/JQuest question" Watch "null reference/JQuest question" New topic
Author

null reference/JQuest question

Weigang Gu
Ranch Hand

Joined: Jan 16, 2001
Posts: 44
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

Joined: Nov 10, 2000
Posts: 73
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

Joined: Jan 16, 2001
Posts: 44
You are right.
thanks
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null reference/JQuest question
 
Similar Threads
jquest
JQuest
JQuest
JQuest: String & StringBuffer
JQuest question