This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I have tested the code,because the "}" is not needed. Or they can't compile. If you delete the last "}", the result is false. Just the static variable "s" isn't initialized. So s==null; null (instanceof String)==false.
Jothi, I think you have got the answer for the output the program produces.
Under which circumstances will the instanceof operator produce a compile time error??
It will produce an error if one will try to compare an instance of and object with an another one which is not in the same inheritance hierarchy except comparision of null(will always return false) .For e.g.
Both String and StringBuffer are sibling parent being the CharSequence,hence are not a part of same inheritance tree. [ December 11, 2006: Message edited by: Sanjeev Kumar Singh ]