What is polymorphic method in java?

后端 未结 5 1511
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 05:39

In the context of Java, please explain what a \"polymorphic method\" is.

5条回答
  •  猫巷女王i
    2020-12-11 06:26

    A polymorphic method is a method that can take many forms. By that that I mean, the method may at different times invoke different methods.

    Let's say you got a class Animal and a class Dog extends Animal and a class Cat extends Animal, and they all override the method sleep()

    Then..

    animal.sleep();
    

    ..can call different methods depending on the dynamic type stored in the variable animal

提交回复
热议问题