
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
18
|
Chapter 2: Object-Oriented ActionScript
speed to, say, the string “very fast.” The following code generates a compile-time
error due to the datatype mismatch:
public var speed:Number = "very fast"; // Error!
// You can't assign a String to a
// variable whose type is Number.
We’ll talk more about datatypes and type mismatches in Chapter 3.
Inheritance
When developing an object-oriented application, we can use inheritance to allow one
class to adopt the method and property definitions of another. Using inheritance, we
can structure an application hierarchically so that many classes can reuse the fea-
tures of a single class. For example, specific Car, Boat, and Plane classes could reuse
the features of a generic Vehicle class, thus reducing redundancy in the application.
Less redundancy means less code to write and test. Furthermore, it makes code eas-
ier to change—for example, updating a movement algorithm in a single class is eas-
ier and less error prone than updating it across several classes.
A class that inherits properties and methods from another class is called a subclass.
The class from which a subclass inherits properties and methods is called the sub-
class’s superclass. Naturally, a subclass can define its own properties and methods in
addition to those it inherits from ...