How to downcast a Java object?

前端 未结 4 1845
时光取名叫无心
时光取名叫无心 2020-12-24 07:54

I am trying to understand Java\'s polymorphism, and I have one question about downcasting an object. Let\'s say for this example I have two subclasses Dog and Cat that inher

4条回答
  •  离开以前
    2020-12-24 08:20

    Here you are talking about downcasting, so in this scenario always superclass should be used as a reference and child object should be pointed by that. This usd basically in factory patter.

提交回复
热议问题