Previous Next Table of Contents

Inheritance


What is inheritance?

Diagram of a bicycle inheritance
Diagram of the bicycle inheritance.
Lifted from The Java Tutorial (Sun Microsystems).

An simple example of inheritance

The following class extends the definition of a Point to three dimensions.
class Point3D extends Point {
        double z;
        
        Point3D (double x, double y, double z) {
                this.x = x;
                this.y = y:
                this.z = z;
        }
        
        public double length() {
                return Math.sqrt(x*x + y*y + z*z);
        }
        
        ...
}

Inheritance and instantiation


Previous Next Table of Contents
J. Anthony Parker, MD, PhD, Tony_Parker@bih.harvard.edu