后期绑定与多态性 - 有什么区别?
我见过两者互换使用,但它们真的意味着相同吗?根据我的理解,多态性延伸了这样一个事实,即您可以通过子类的实例交换类的实例,而后期绑定意味着当您调用实例的方法时,类型决定调用哪个方法(子类/超类) 。
I've seen both used interchangebly but do they really mean the same? From my understanding, Polymorphism stretches the fact that you could exchange an instance of a class by an instance of a subclass, and Late Binding means that when you call a method of an instance, the type decides which method (subclass/superclass) gets called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,但我认为重要的是要明确多态性不仅与继承有关,而且与接口有关(如果不是大多数的话)。通过多态性,您可以使用实现该接口的所有其他类来实例化一个接口I,并且当调用该接口的方法时,将调用用于实例化该接口的类的方法。
后期绑定意味着,当您调用方法时,将在运行时检索调用该方法的特定对象。
You're right, but I think it's important to specify that the polymorphism it's not only related to inheritance but also, if not most, about interfaces. Through polymorphism you can instantiate an interface I with every other class that implements that interface and, when the method of the interface is called, the method of the class used to instantiate the interface is called.
Late Binding means that, when you call a method, the specific object on which that method is called is retrieved at runtime.