LINKS

Java Tutor Homepage

Java Applications and Components

Java Applets and Components

Java Frequently Asked Questions:
    1. What is Inheritance?
    2. What is Polymorphism?
    3. What is Encapsulation?
    4. Avoiding the Divide by Zero Error
    5. Public Classes in Java Source Files
    6. The Import Statement in Java
    7. Classes with Default Access
    8. What are Local Variables?
    9. What is an Abstract Method?
    10. Data Structures
    11. What is Autoboxing and Auto-Unboxing?
    12. What is multithreading?
    13. What are Threads?
    14. Thread States
    15. What is the Purpose of Synchronization?
    16. Thread Interaction
    17. Can You Start a Thread Twice?

Java FAQ 2 - What is Polymorphism?

Polymorphism is a way for an object of an abstract class to gain the methods and variables of another class that is not abstract. The non-abstract class must have methods for all of the abstract methods of the abstract class. Let’s revisit the Vehicle example from the Inheritance FAQ. While the subclasses inherited methods and variables from the superclass in that example, in this example, an object of the abstract Vehicle class can receive the methods of another class, say the Sedan class. The Vehicle class in affect becomes an object of the Sedan class.

The following diagram is an example of Polymorphism:
Diagram of Polymorphism

The abstract Vehicle class can receive the methods from any of these other four classes, Sedan, Coupe, SUV, and Pickup, as long as these classes have non-abstract methods for any abstract methods in the Vehicle class.