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 1 - What is Inheritance?

Inheritance is a way to reuse code that has already been written. Some basic terminology about inheritance is useful to gain an understanding of it. The “superclass” is the class which will be inherit by the “subclass”. By declaring one class (that is the subclass) to inherit (by using the “extends” command) from another class (that is the superclass), the new class receives all of the public methods and variables from the superclass. The subclass also receives that ability to call private methods of the superclass by using the “super.classname( )” command.

The following diagram is an example of inheritance:
Diagram of Inheritance

All four of the subclasses, Sedan, Coupe, SUV, and Pickup inherit all public methods and variables from Vehicle, the superclass.