Given the following code:
What is the outcome?
The object created is a DerivedB. Both casts succeed because DerivedB inherits from DerivedA and Base. Overridden instance methods use runtime dispatch, so both calls to test() invoke DerivedB.test(), producing DerivedB DerivedB.
DerivedB
DerivedA
Base
test()
DerivedB.test()
DerivedB DerivedB
Community Discussion