JavaBeat Certifications Certifications Kits Articles Interview Questions OCAJP 7 OCPJP 5 OCPJP 6 OCEJWCD 6 SCBCD 5.0 SCEA SCJA

advantages of polymorphishm in Java

Topic :
Feedback Request New QnA Print Email

One of the most important advantages of polymorphism is that it allows you to separate interface from implementation. You can for example do this:

List<String> names = new ArrayList<String>();

Note that the type of 'names' is List<String>: the name of an interface, instead of a particular implementation of the interface. The rest of the program can use the list 'names' and doesn't need to know what particular implementation of the List interface is used. If you for some reason to decide to use a different implementation, for example LinkedList:

List<String> names = new LinkedList<String>();

Then you'd have to change only this one line in your source code, and the rest of the program would still work without changes.

This is possible because of polymorphism.

Topic :
Feedback Request New QnA Print Email

All api java java 6.0 java 7.0 jdbc jsp servlet ejb jndi jms ejb 3.0 j2ee jee 5.0 jee 6.0 jsf struts spring Hibernate ajax JBoss Seam netbeans eclipse ant xml maven dojo junit javafx j2me log4j ESB JBoss Apache Quartz scjp mysql oracle gwt openjpa jmx yui google-guice android JBoss scwcd 5.0 scjp 1.5 scjp 1.6 scja scbcd 5.0

javabeat | advertise | about us | contact | useful resources
Copyright (2004 - 2013), JavaBeat