Guard a downcast with instanceof
Guard a downcast with instanceof
Answer
if (v instanceof Car) { Car c = (Car) v; c.honk(); }
`instanceof` confirms the real type before the explicit downcast, so the `(Car) v` cast can never throw `ClassCastException` and `v` being null is ruled out.