PPT Slide
Keyword instanceof: Used to interogate an object to see if it is an instance of the specified class, e.g.
“Is this particular animal of class Dog?”
If Java can determine that a given Animal is or is not a Dog (via instanceof), then:
- Why the need to cast it to a Dog object before Java can recognize that it can bark?
- Why can’t Java do it for us?