The whole point of the instanceof operator is to determine the "runtime type" of an object. This becomes an issue because, with inheritance, you can use a child object anywhere a parent is expected. Therefore, the following is legal:
You see, we are assigning an Animal reference to a Cat object. This is perfectly legal because a Cat "is a" Animal.
However, a can not reference just any old class. For example, you can't reference a String object because a String "is not a" Animal. The following would give you a compiler error:
You're getting an error message because you're
testing to see if an object is of a type that it can't possibly be. There is no way that the object referenced by t could be a String object because String does not extend Ticker. In short, String "is not a" ticker.
That's why you're getting the error message. I hope that helps,
Corey
P.S. I realize you're new to the forums, Kathy, but I would appreciate if you would insert "CODE" tags around your code when you post some. It helps retain the formatting which makes it much easier to read. You can check out
this page for details about how to use UBB tags in your posts and there is also a series of buttons beneath "Instant UBB Code" that will help you insert proper tags.
If you can put those tags in there to begin with, you not only reduce my workload (I won't have to edit your posts), but you'll also make it easier for other people to understand and respond to your posts.
Thanks.
[ February 25, 2004: Message edited by: Corey McGlone ]