INH - Inheritance Overview
Inheritance
Introduction
In Java, all classes are part of an immense hierarchy, with the Object class at the root. Each class inherits characteristics (variables and methods) from previous classes along the hierarchy. A class can add new variables to these inherited characteristics as needed. It also adds new methods and/or modifies inherited methods. Inheritance provides a mechanism for reusing code and can greatly reduce the effort required to implement a new class.
Module Lessons Preview
In this module, we will study the following topics:
Creating Superclasses and Subclasses: One of the strongest advantages of Java is the ability to categorize classes into hierarchies through inheritance. Creating objects, calling methods on the objects created, and being able to define a new data type by creating a class will be reviewed in this lesson in order to understand inheritance.
super Keyword: Certain existing classes can be extended to include new behaviors and attributes without altering existing code. The keyword super will be used to access a superclass’s constructor and methods.
Overriding Methods: Newly created classes, called subclasses, will often override methods from superclass. This lesson will show how child classes can redefine methods from the parent class.
Creating References Using Inheritance Hierarchies: Recognizing common attributes and behaviors between classes in a hierarchy help show how subclasses extend superclasses. When creating subclass objects references can be made from multiple places in the hierarchy.
Polymorphism: Recognizing and utilizing existing hierarchies will help make programs more readable and maintainable. In this lesson, we will see how a method in an inheritance hierarchy can have multiple meanings.
IMAGES CREATED BY GAVS