In the above code the instanceof operator is spelled incorrectly as instanceOf, by making the "O" of "of" capital.In this situation why is the compiler outputs an error message advising to include a parenthesis at the left hand side of obj1 and other error messages
Compiler error recovery is a very tricky topic. I think the only way you can really get a feel for the issues involved is by writing some compiler yourself. Basically, while it's easy to write a program that recognizes correct source code, it's exceedingly difficult to write one that recognizes the true intent of invalid source.
my guess is that it thinks you are trying to cast a reference you are declaring. In other words, it thinks you are declaring a reference you name 'Parent' of the type 'instanceOf', and are trying to cast it to a reference of type 'obj1'.
(obj1) instanceOf Parent;
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by sivakumar janardhanan: Hi Varuna, i think instanceOf is not a java keyword. that why the compiler gives an error message. now you use this java keyword "instanceof" instead of "instanceOf". it will execute properly.