Consider the following:
What is the outcome?
The reference b2 has runtime type C, which cannot be cast to sibling subclass B. The downcast at line n1 throws a ClassCastException, and normal execution stops before line n2 or either test() call can run.
b2
C
B
ClassCastException
test()
Community Discussion