Why cast after an instanceOf?

前端 未结 11 1871
情歌与酒
情歌与酒 2020-11-30 11:05

In the example below (from my coursepack), we want to give to the Square instance c1 the reference of some other object p1, but only i

11条回答
  •  一生所求
    2020-11-30 11:46

    If c1 is declared as a type of Square then casting is required. If it is a declared as an Object then casting is not needed.

提交回复
热议问题