Inheritance


Inheritance is a very powerful and useful functionality that allows you to define a class that extends the capabilities of another class. You can build upon something that already exists. Inheritance provides a mechanism for creating hierarchies of related classes. Java allows only single inheritance. A class can have only one direct superclass, which itself can have only one superclass, and so on. This is in contrast to a language such as C++ that allows a class to inherit from multiple superclasses.

A subclass has access to all the nonprivate members of its superclass. The subclass also has access to the nonprivate members of the superclass of its superclass and so on up the inheritance hierarchy. Inheritance facilitates code reuse and reduces duplication of effort. You can declare a member used by multiple classes inside a superclass higher up the class hierarchy. All descendant classes can then access the member.

Inheritance also enables the concept of polymorphism.. An abstract superclass can declare the methods that must be implemented by subclasses without specifying the details of the implementation. More details on inheritance and how to use it are provided in Chapter 7.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net