Type a downcast guarded by instanceof
Type a downcast guarded by instanceof
Answer
if (a instanceof Dog) { Dog d = (Dog) a; d.fetch(); }
instanceof tests whether the object's runtime type is Dog (or a subclass). Without this guard, the cast might throw ClassCastException if a holds a non-Dog.