Understanding polymorphism
Polymorphism is one of the defining features of object-oriented languages. Java has expanded the concept by including interfaces. Let us begin with a simple hierarchy of classes as shown here:
public class SuperClass { protected int count; public void setCount(int count) { this.count = count; } public void displayCount() { System.out.printf("SuperClass count = %d%n", count); } }
In this trivial class, we have a public method to assign a value to count
and a second method that displays the value in count
along with the name of the class. In the following code block, we have a class that uses SuperClass
:
public class Polymorphism { private...