Hi guys, I have 2 questions regarding the following code. First question, why is it that null here is considered as a string and it would run if I will not include the object created with whatever. Second question, why do I get an error msg when I include whatever that it cannot resolve symbol?
[This message has been edited by Cindy Glass (edited October 25, 2001).]
ok, I'm not sure what you're asking here Mag...I compiled the code, but put quotation marks around "whatever" to make it a String. The output was: String String. But I'm still not sure what you're asking?? ------------------ Michael J Bruesch Codito, ergo sum... I code, therefore I am. [url = http://www.geocities.com/mjbruesch/games]My Java Games, I'm quite proud[/url]
Michael J Bruesch<br /><i>I code, therefore I am.</i>
Hi Margaret, 'null' is really a 'null literal'. It's valid in Java and can be legally assigned to an Object; which is why <code>new Sample(null)</code> works. It gets treated as a String vs an Object because, when given a choice between two methods where the argument is valid for both parameters, the compiler will always choose the most specific parameter as a match. In this case, 'null' is a literal that can be handled as an Object and a String. String is more specific so the compiler uses <code>Sample(String s)</code> vs <code>Sample(Object o)</code> 'whatever' has no meaning in Java; it's not a literal or a built-in object and you haven't given it any definition so the compiler doesn't know what it is and gives you an error. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform