is Polymorphism also applies in Abstract Classes?

2019-09-21 18:59发布

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?

标签: java oop
2条回答
成全新的幸福
2楼-- · 2019-09-21 19:28

Yes. That is polymorphic.......

查看更多
再贱就再见
3楼-- · 2019-09-21 19:30

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

That "argument" is factually incorrect.

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?

查看更多
登录 后发表回答