is Polymorphism also applies in Abstract Classes?

2019-09-21 18:43发布

问题:

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?

回答1:

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?



回答2:

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



标签: java oop