![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
One of the primary benefits of object-oriented programming is that you can create subclasses of a class; the subclass then inherits all the properties and methods of the superclass. The subclass typically defines additional methods and properties, or extends the superclass. Subclasses can also override (provide their own definitions for) methods inherited from a superclass.
For example, you might create a Mammal class that defines certain properties and behaviors common to all mammals. You could then create a Cat class that extends the Mammal class. In this way, inheritance can promote code reuse: instead of recreating all the code common to both classes, you can simply extend an existing class. Another subclass, in turn, could extend the Cat class, and so on. In a complex application, determining how to structure the hierarchy of your classes is a large part of the design process.
In ActionScript, you use the extends
keyword to establish inheritance between a class and its superclass. For more information, see Creating subclasses.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |