0

基本面向对象问题...

我想在 Array 类中添加几个函数,这样我的程序就会很棒,让我一夜成名。

所以我创建了一个新的子类 NewArray,它扩展了 Array。我需要为 NewArray 编写构造方法吗?如果我把它留空,它会只使用父级(数组)的构造方法吗?

谢谢

4

1 回答 1

4

Yes, if you leave it blank it'll use the super-class' default constructor, which in the case of an Array is actually a constructor with a default value set:

Array(numElements:int = 0)

So by default you'll be creating an array with zero elements, which I guess is probably what you want anyway.

And don't forget this note from the docs:

You can extend the Array class and override or add methods. However, you must specify the subclass as dynamic or you will lose the ability to store data in an array.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html

于 2010-01-09T20:19:55.707 回答