posted 24 years ago
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