Dynamic Binding Java. Does an object have the methods of its declared type, or its actual type? [duplicate]
问题 This question already has answers here : Difference between Dynamic and Static type assignments in Java (5 answers) Closed 4 years ago . Say I declare the following: Cat elsa = new Lion(); Lion extends Cat. If I declare it this way, will elsa be a cat having All of the methods of a cat or will it be a Lion, having all of the methods of both lion and cat This exact question is not addressed in other questions that I could find. 回答1: The object you create is of type Lion and has all of the