覆盖与多态 [英] OverRiding Vs PolyMorphism

查看:40
本文介绍了覆盖与多态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者有什么区别?

具有 myMethod(int a) 的超类和具有相同方法的继承类,这是覆盖还是多态?

A super class having myMethod(int a) and an inheriting class having the same method, Is this overriding or polymorphism?

我很清楚黑白覆盖和重载的区别,但多态性和覆盖似乎是一样的.还是他们?

I am clear with the difference b/w overriding and overloading, but the polymorphism and overriding seems the same. Or are they?

推荐答案

重写是当你在一个对象上调用一个方法,而子类中与超类中具有相同签名的方法被调用.

Overriding is when you call a method on an object and the method in the subclass with the same signature as the one in the superclass is called.

多态是指您在运行时不确定对象类型并调用最具体的方法.因此,调用的方法的行为可能会有所不同,具体取决于运行时的对象类型.

Polymorphism is where you are not sure of the objects type at runtime and the most specific method is called. Therefore the behaviour of the method called may differ, depending on the objects type at runtime.

覆盖是一种多态性以及重载和动态(后期)绑定.您可以查看更多详细信息 这里是关于不同类型的.

Overriding is a type of polymorphism along with overloading and dynamic (late) binding. You can see more details here about the different types.

这篇关于覆盖与多态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆