What is the difference between up-casting and down-casting with respect to class variable

后端 未结 10 1870
暗喜
暗喜 2020-11-22 09:55

What is the difference between up-casting and down-casting with respect to class variable?

For example in the following program class Animal contains only one method

10条回答
  •  耶瑟儿~
    2020-11-22 10:09

    Maybe this table helps. Calling the callme() method of class Parent or class Child. As a principle:

    UPCASTING --> Hiding

    DOWNCASTING --> Revealing

    enter image description here

    enter image description here

    enter image description here

提交回复
热议问题