多态性是否也适用于抽象类? [英] is Polymorphism also applies in Abstract Classes?

查看:68
本文介绍了多态性是否也适用于抽象类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个常见的论点是多态只适用于接口而不适用于抽象类.

A common argument is that Polymorphism only applies to interfaces and not abstract classes.

抽象父类与扩展它的具体类的关系是否被视为多态?

Is the relationship of as Abstract parent class to a concrete class that extends it considered a polymorphism?

List list = new Arraylist()// Polymorphism as List is an interface
AbstractClass parent = new Child(); // Is this also considered polymorphic?

推荐答案

常见的论点是多态性仅适用于接口的代码,而不适用于抽象类.

Common argument is Polymorphism only applies to Code to interface and Not abstract classes.

那个论点"实际上是不正确的.

That "argument" is factually incorrect.

多态工作在 Java 中都很好,无论您使用的是接口、抽象类还是非抽象类.(关于哪种最有利于长期可维护性存在问题,但这是一个不同的话题.)

Polymorphism works just fine in Java whether you are using interfaces, abstract classes or non-abstract classes. (There are questions about which is best for long term maintainability, but that is a different topic.)

我很好奇你是从哪里找到那个论点"的.你能提供一个网址吗?

I'd be curious where you found that "argument". Can you provide a URL?

这篇关于多态性是否也适用于抽象类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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