My doubt, if this is so, i accept, but still it is legal. the implications of this is test=false. that is it. how come the option is wrong??? it is legal, but false...

please help o'veterans..

John Stone

Ranch Hand

Posts: 332

posted 10 years ago

because compiler can at compile-time tell, that t (Ticker) is not related to String. Compiler knows that Ticker is not ancestor nor descendant of String, and consider parameters (of instanceof) as incompatible.

try to change t to Object variable

and now it is working. t is of type Object, so it is possible to have String object reference in type Object reference (upcasting).

when t is Ticker, it doesn't look like upcasting, doesn't look like downcasting, and you have compile-time error: incompatible types

> please help o'veterans :-)

Barry Gaunt

Ranch Hand

Posts: 7729

posted 10 years ago

Hello "java ojava"-

Welcome to JavaRanch.

On your way in you may have missed that we have a JavaRanch Naming Policy for displayed (screen) names. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Since yours "java ojava", does not conform with it, please take a moment to change it, which you can do right here.

Posters with nonconforming displayed names will be locked out of JavaRanch after a few posts using those names.