简体   繁体   中英

Which method is called when Object is typecasted to parent

I know that this must have been asked before, but I'm not sure how to search for this.

If I have a Object of class B that extends class A, If I type cast this object to class A and then call a overriden method on this object, which method will be called? A's or B's?

The real class of an object determines with methods are called.

Those casts, and types that you are using in your source code are not really meaningful at runtime. You rather look at them as a way to enable human coders to do their job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM