B is not Cat, B is Animal. The inferred type of add is then effectively:
def add(element: Animal)
You are able to pass Cat here because Cat extends Animal.
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.