Game Development Reference
In-Depth Information
public function helloWorld():void {
trace( " HELLO WORLD " );
package {
class SubClass extends SuperClass {
public function SubClass() {
trace(name); //OUTPUTS " SuperClass "
trace(_number); //OUTPUTS 5;
trace(_packageNumber); //OUTPUTS 7.5
helloWorld(); //OUTPUTS " HI WORLD " ;
super.helloWorld(); //OUTPUTS
trace(_secretNumber); //THROWS ERROR;
override public function helloWorld():void {
When SubClass traces out properties it has inherited from
SuperClass, they stay intact, with the exception of the private
variable. Also, when helloWorld is run from SubClass, it traces a
different message than when run from SuperClass. That said, there
is a way to get at the SuperClass implementation of helloWorld
through the use of the super keyword. Super returns a reference to
the superclass of the current class, allowing you access to any
methods you may have overridden.
One of the most commonly misunderstood (including by myself for
a long time) aspects of object-oriented programming (OOP) is the
concept of interfaces . It is confusing for a few reasons, not the least
of which is the confusion of an OOP interface with a graphical user
interface (like operating systems provide). An interface does not
contain any code, outside of declaring the public methods that a
class will use and what each will accept as parameters and what
each will return. If a class is like a blueprint of the specific direc-
tions for creating a new instance of that class, an interface is like a
checklist for that blueprint to make sure it adheres to a certain spe-
cification. Perhaps the best way to understand how an interface is
structured is to see one in code.
Search Nedrilad ::

Custom Search