26 | Chapter 1: Object-Oriented Programming, Design Patterns, and ActionScript 3.0
Any class that uses theextendsstatement to declare a class inherits the class charac-
teristics it extends. The class that’s extended is thesuperclass(or parent). The class
that extends another class is thesubclass. Both theDogandCatclasses are subclasses
of theQuadPetsclass. They inherit all the superclass’ functionality. To see how that
happens, we’ll have to first create the two subclasses.
To see how theDogandCatclasses inherit the operations of the superclass, the
TestPetsclass simply invokes the single method (makeSound) from the superclass. As
you can see from theDogandCatclasses, no such method can be seen in their con-
struction, and so you can see that it must have originated in theQuadPets class.
trace("Superclass:Pet Sound");
}
}
}
Example 1-14. Dog.as
package
{
public class Dog extends QuadPets
{
public function Dog( ):void
{
}
public function bark( ):void
{
trace("Dog class: Bow wow");
}
}
}
Example 1-15. Cat.as
package
{
public class Cat extends QuadPets
{
public function Cat( ):void
{
}
public function meow( ):void
{
trace("Cat class: Meow");
}
}
}
Example 1-13. QuadPets.as (continued)