| Author |
how Interface supports polymorphism?
|
kiran nyala
Greenhorn
Joined: Sep 21, 2009
Posts: 23
|
|
hi
i understand that an interface can implement by any number of classes so that we can say that interface supports polymorphism.
is my view correct?
Why we assign subclass object to super class reference in case of class inheritance and also in case of interface implementation? could you please explain
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
Please use text colouring only for highlighting.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
Your second question is a frequently asked question on the forums here. Look at the following example:
The good thing about the first version is that the rest of the application that uses the list does not need to know what kind of list exactly it is - the only thing that's important is that it is a list. Because of this, you could easily change the exact type of the list if you later find out that that would be more efficient, for example:
For the rest of the application, names is still a List<String>, so you would not have to change anything in the rest of the application.
It's the principle of program to an interface, not an implementation.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: how Interface supports polymorphism?
|
|
|