The dictionary definition of polymorphism refers to a principle in biology in which an organism or species can have many different forms or stages. This principle can also be applied to object-oriented programming and languages like the Java language. Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class.
Polymorphism can be demonstrated with a minor modification to the
Polymorphism can be demonstrated with a minor modification to the
Bicycle
class. For example, a printDescription
method could be added to the class that displays all the data currently stored in an instance.public void printDescription(){
System.out.println("\nBike is " + "in gear " + this.gear
+ " with a cadence of " + this.cadence +
" and travelling at a speed of " + this.speed + ". ");
}
for more detail visit
http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html
No comments:
Post a Comment